hi, im trying to make water which kills you and i need it to play a sound effect when it's touched.
this is the script i came up with:
function onTouch(part)
script.Parent:Play()
end
thanks in advance, from poopypigeon245
hi, im trying to make water which kills you and i need it to play a sound effect when it's touched.
this is the script i came up with:
function onTouch(part)
script.Parent:Play()
end
thanks in advance, from poopypigeon245
function onTouch (part)
script.Parent:Play()
end
script.Parent.Touched:connect(onTouch)
What you did wrong was that you weren't connecting the function. You were just saying what the function does. The last line of code basically connects the function 'onTouch' to script.Parent.Touched (when part is touched).
it didnt work
Oops. Change the last line (script.Parent) to wherever your part is located.
Well, the function is not connected. You can try the following:
local CanPlay = true -- To prevent the song from playing multiple times.
local CanKill = true
function Play(hit)
local Song = workspace.YourSong
if hit.Parent:IsA("Model") and hit.Parent:FindFirstChild("Humanoid") then -- We check for a humanoid and if the hit's parent is a Model.
if CanPlay and CanKill then -- If CanPlay and CanKill are true.
hit.Parent:BreakJoints() -- We kill the Character.
CanPlay = false
CanKill = false -- We set both variables to false.
Song:Play() -- We play the song.
wait(5) -- 5 Second delay.
CanPlay = true
CanKill = true -- We set both variables to true.
end
end
end
script.Parent.Touched:connect(Play) -- In my case, I parent the script to the Part.
Hope that helped. (Sorry for any mistakes, grammar mistakes or bad explanation.)
-AlessandroG200
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
script is a child of the sound
Not sure if this'll work, but try it: