Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Check if player has touched any type of brick?

I know

game.Workspace.ball.Touched:connect()

Will activate whenever a brick touches the brick ("ball") in the script. But what if there are multiple bricks named ball in workspace, and I want the script to activate whenever any of them are touched? How would I achieve that?

2 comments

0

Hey, I fixed the script. Look at it.

0

By using a 'for' loop to loop through all the children, the 'function' for the '.Touched' event, the 'GetChildren' method to get all the current children in the Parent [Parent:GetChildren()], and the '.Touched' event to fire whenever the part(s) are touched.

2 answers

✓ Accepted answer
local ball = workspace:GetChildren() 
for i=1, #ball do 
if (string.lower(ball[i].Name) == "ball") then 
ball[i].Touched:connect(function(hit)

--Chunk

end)
end 
end 

Do something like that. The scripts check for a part named "Ball" and if something touches it, the function triggers.

3 comments

0

What's "d"?

0

I'm assuming Ball should be lowercase? Still doesn't seem to work...

0

Okay I get what's wrong, you weren't really answering my question. I want the script to function when the player touches ANY part named ball in the Workspace. Not with just one part named ball.

zerio you are requesting which is really against the rules

This discussion is preserved as it was. New answers, comments, and votes are closed.