|
| 10 Aug 2014 09:43 PM |
function onHit(hit) print("Found!") end
for i,v in pairs(game.Workspace.AllPartss:getChildren()) do if v:IsA("Part") then for i = 1,2 do if v.Name == "Parts"..i then v.Touched:connect(onHit) end end end end
All i wanted to do is findd the two parts that are named Parts1 and Parts2, like when i touch one of the parts it says "Found!" in the print but it doesn't seem to be working? Can i get any help on what i did wrong?
|
|
|
| Report Abuse |
|
|
iiEssence
|
  |
| Joined: 18 Jun 2014 |
| Total Posts: 3467 |
|
|
| 10 Aug 2014 09:46 PM |
function onHit(hit) print("Found!") end
for i,v in pairs(game.Workspace.AllPartss:getChildren()) do if v:IsA("Part") then if v.Name:sub(1,5) == "Parts" then -- :sub(1,5) = 1st letter to 5th letter v.Touched:connect(onHit) end end end |
|
|
| Report Abuse |
|
|
|
| 10 Aug 2014 09:54 PM |
| Oh so it's to Part1 to Part5? |
|
|
| Report Abuse |
|
|
iiEssence
|
  |
| Joined: 18 Jun 2014 |
| Total Posts: 3467 |
|
|
| 10 Aug 2014 09:57 PM |
No, "Parts" has 5 letters right?
What :sub() does is it "cuts" the name off.
So instead of getting the whole name, it would check if the first 5 letters of the part's name is "Parts" |
|
|
| Report Abuse |
|
|
|
| 10 Aug 2014 09:59 PM |
So if i touched any part that includes what you say it will really print ("Found!") and work smoothly? If so i'll try that now :3 |
|
|
| Report Abuse |
|
|