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

How might I be able to add sound to a script when on impact?

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?

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)

2 comments

0

What if the sound doesn't exist?

0

put this into the part and add the sound with it

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