Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Check if player has touched any type of brick?

Asked by
Zerio920 285 Moderation Voter
9 years ago

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?

0
Hey, I fixed the script. Look at it. EzraNehemiah_TF2 3552 — 9y
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. TheeDeathCaster 2368 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago
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.

0
What's "d"? Zerio920 285 — 9y
0
I'm assuming Ball should be lowercase? Still doesn't seem to work... Zerio920 285 — 9y
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. Zerio920 285 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

zerio you are requesting which is really against the rules

Answer this question