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

How can I make a sound play when a brick touches another brick?

Asked by 3 years ago

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.

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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

Ad

Answer this question