|
| 06 Jan 2013 04:08 PM |
| Check if a model is a certain name through get children, and fire a touched event if it has that name? If so, show me how. |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:10 PM |
if model:FindFirstChild("Name") then -- model contains an object with the specified name in its immediate descendants. end
|
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:11 PM |
what like? script.Parent.Touched:connect(function(hit) if hit.Parent ~= Workspace then for i,v in pairs(hit.Parent:GetChildren()) do if v.Name == "TheName" then --do stuff end end end end) |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:12 PM |
| I am trying to find multiple models. I am trying to use get children to make it fire for those specific parts in those models. There is no use for FindFirstChild. Did you even read it? |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:12 PM |
| mmm... yeah i over complicated that, findFirstChild would be WAY better to use in the case. :P |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:13 PM |
Something like this:
g = game.Workspace.Doors:GetChildren()
for i = 1, #g do if g[i].Name == "Door" then g[i].Part.Touched:connect(function(hit) |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:13 PM |
| oh double mistake then, so mine may work for your needs then :o? |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:13 PM |
| Did you guys even read? I need it to find multiple models. ._. |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:14 PM |
| Nevermind. I'll try out your script and see what happens. |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:15 PM |
| Wait. I want it to work outside the part. Not inside a part. It would be messy to post all of that inside each brick |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:15 PM |
ohhhhhhhhhhhhhhhh.... ok lets hope i dont make for late toast...
for i,v in pairs(Model:GetChildren()) do if v.Name == "Door" then v.Touched:connect(function(hit) -- door stuff end end
|
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:17 PM |
| This would make perfect for RPG doors where you only have to chnage the level value inside of them and it works in one neat script wouldn't it? It would cause less lag than before. |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:18 PM |
q-q q-q q-q im a failure because i keep replying to quickly for a,b in pairs(Workspace:GetChildren()) do if v.Name == "ModeName" then for i,v in pairs(b:GetChildren()) do if v.Name == "Door" then v.Touched:connect(function(hit) -- door stuff end) end end |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:18 PM |
You can not "Fire" A touch event. You can attach an event to your function, if that is what you mean.
local a = model:GetChildren() for i = 1,#a do if a[i].Name == "NameHere" then a[i].Touched:connect(function(hit) -- end) end end
Something like that should for for this case.
|Paradoxical| I shun thy heathen, dost thou not know that flames will devour thy mind? |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:18 PM |
| All doors will run on one script and all of them will have values so you can check the level without a seperate script. Neat isn't it? |
|
|
| Report Abuse |
|
|
hunte922
|
  |
| Joined: 28 May 2008 |
| Total Posts: 6969 |
|
|
| 06 Jan 2013 04:19 PM |
This is most likely what you're looking for:
AdornName = "Name" SearchDirectory = script.Parent
function PartTouched(hit) if touched ~= nil then local touchedx = touched --do stuff (touchedx is the part that was hit, hit is the part that hit) end end
for i, v in pairs(SearchDirectory:GetChildren()) do if v.Name == AdornName and v:IsA("BasePart") then v.Touched:connect(function () touched = v; PartTouched(); end) end end
|
|
|
| Report Abuse |
|
|
hunte922
|
  |
| Joined: 28 May 2008 |
| Total Posts: 6969 |
|
|
| 06 Jan 2013 04:20 PM |
| Mine gives you the part that hit and the part that got hit - you'll need it the most I'd assume. |
|
|
| Report Abuse |
|
|
hunte922
|
  |
| Joined: 28 May 2008 |
| Total Posts: 6969 |
|
|
| 06 Jan 2013 04:21 PM |
Pardon me, there was a slight error...
This is most likely what you're looking for:
AdornName = "Name" SearchDirectory = script.Parent
function PartTouched(hit) if touched ~= nil then local touchedx = touched --do stuff (touchedx is the part that was hit, hit is the part that hit) end end
for i, v in pairs(SearchDirectory:GetChildren()) do if v.Name == AdornName and v:IsA("BasePart") then v.Touched:connect(function (oldhit) touched = v; PartTouched(oldhit); end) end end |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:27 PM |
So would this work?
local a = game.Workspace.Doors:GetChildren()
for i = 1,#a do Door = a[i] if Door.Name == "Door" then Door.Touched:connect(function(hit) local player = Door.Part:GetPlayerFromCharacter(hit.Parent) end if (player.leaderstats.Level.Value >= Door.Level.Value) then for i = 1,10 do Door.Part.Transparency = i/10 end Door.Part.CanCollide = false wait(2) for i = 1,10 do Door.Part.Transpaency = Door.Part.Transparency - 1 end wait(1) Door.Part.CanCollide = true end) end end
|
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:28 PM |
| hunte, could you explain to me how that works. That level of scripting is moderately unknown to me. |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:29 PM |
| Slight error in my script. Transparency is spelled wrong. |
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:30 PM |
| Everything looks like it should work in your script. though for saftey precautions i would check if the part hit is nil (to avoid errors from thing that remove themselves when they hit something) |
|
|
| Report Abuse |
|
|
hunte922
|
  |
| Joined: 28 May 2008 |
| Total Posts: 6969 |
|
|
| 06 Jan 2013 04:35 PM |
| I tried to keep it simple. You can enter in a name to search and a directory to search in the top 2 lines, as well as put any code within the annotation line. |
|
|
| Report Abuse |
|
|
hunte922
|
  |
| Joined: 28 May 2008 |
| Total Posts: 6969 |
|
|
| 06 Jan 2013 04:43 PM |
--Here's some tested code that fits your needs:
AdornName = "Door" SearchDirectory = workspace.Doors
function PartTouched(hit) if touched ~= nil then local touchedx = touched --do stuff (touchedx is the part that was hit, hit is the part that hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then if (player.leaderstats.Level.Value >= touchedx.Level.Value) then for i = 1,10 do if touchedx == nil then return end touchedx.Part.Transparency = i/10 wait() end if touchedx == nil then return end touchedx.Part.CanCollide = false wait(2) for i = 1,10 do if touchedx == nil then return end touchedx.Part.Transpaency = 1 - (i/10) wait() end wait(1) if touchedx == nil then return end touchedx.Part.CanCollide = true end end end end
for i, v in pairs(SearchDirectory:GetChildren()) do if v.Name == AdornName and v:IsA("BasePart") then v.Touched:connect(function (oldhit) touched = v; PartTouched(oldhit); end) end end
|
|
|
| Report Abuse |
|
|
|
| 06 Jan 2013 04:46 PM |
Look in my models for an example But let me update it in one minute... |
|
|
| Report Abuse |
|
|