generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: What did i do wrong?

Previous Thread :: Next Thread 
RobloxAssociated is not online. RobloxAssociated
Joined: 30 Oct 2011
Total Posts: 449
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 is not online. 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
RobloxAssociated is not online. RobloxAssociated
Joined: 30 Oct 2011
Total Posts: 449
10 Aug 2014 09:54 PM
Oh so it's to Part1 to Part5?
Report Abuse
iiEssence is not online. 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
RobloxAssociated is not online. RobloxAssociated
Joined: 30 Oct 2011
Total Posts: 449
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image