How might I be able to add sound to a script when on impact? I have a touchable explosion brick, but how do I add the 'explosion' sound to it?
COMMUNITY QUESTION
How might I be able to add sound to a script when on impact?
2 answers
script.Parent.Touched:connect(function()
local sound = Instance.new("Sound", script.Parent) --Second argument is the parent
Sound.SoundId = SoundIdHere --Replace this with a sound ID
Sound.Volume = 1
Sound.Pitch = 1
Sound:play()
wait(Sound.TimeLength) --I don't think this works yet.
Sound:remove() --Or :Destroy()
end)
This script adds a sound with the explosion sound when touched by anything.
****Put into a part with the sound you want it to play, Change ONLY WHATS ASKED
Sound = Script.Parent:FindFirstChilD("SOUNDNAMEHERE") -- Replace with name of song
function onTouched(hit)
Sound:Play()
end
script.Parent.Touched:connect(onTouched)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
What if the sound doesn't exist?
put this into the part and add the sound with it