I'm making a soccer/football game and I want a cheering sound to play when the ball touches the goal line. How do I do that? Please explain the script specifically and where I should add the part names. Thanks.
How can I make a sound play when a brick touches another brick?
1 answer
im assuming you want the sound to play when the ball goes through the net in general and not just when it touches the line on the ground, so my suggestion is to put an invisible brick covering the entire entrance of the net, with canCollide set to false.
inside that brick, put the sound you want to play for a goal (ill call it "GoalSound" but you can call it whatever as long as you change it in the script too). next put a script in the brick and then connect a function to the touched event which will detect all bricks which touch it.
you only want the ball to trigger the sound so call the ball "Ball" and have the script check for that name
local net = script.Parent
net.Touched:Connect(function(toucher)
if toucher.Name = "Ball" then
net.GoalSound:Play()
end
end)
there is more to do like making sure the ball doesnt trigger the sound on the way out, but this should get you started
This discussion is preserved as it was. New answers, comments, and votes are closed.
