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

Death Sound Playing Only After Respawn?

Asked by 9 years ago

I have this script that makes a Gui Appear and a Sound to play when you die.

The problem is, the Gui Appears, but the Sound plays only after respawn.

I have tried waiting longer times and dying many times, but it still plays after the respawn.

This is the script I used:

P = script.Parent.Parent.Parent.Parent.Character.Humanoid

while true do

if P.Health == 0 then
script.Parent.Parent.Parent.Death:Play()
script.Parent.Visible = true
end
wait()
end

2 answers

Log in to vote
1
Answered by 9 years ago
P = script.Parent.Parent.Parent.Parent.Character.Humanoid

while true do

if P.Health == 0 then 
script.Parent.Parent.Parent.Death:Play()
script.Parent.Visible = true
end
wait()
end

What this script does is it constantly checks if Health is 0, and when it is, plays a sound. What's wrong with that is that when Health is 0, it plays the audio and then keeps checking if health is 0, causing the audio to keep playing until health isn't 0 (When you respawn).

A working version of your script would be:

P.Died:connect(function() --When P dies, do the following
    script.Parent.Parent.Parent.Death:Play()
    script.Parent.Visible = true
end)
Ad
Log in to vote
0
Answered by 9 years ago

You can use the Died event to tell when a humanoid has died.

P.Died:connect(function()
script.Parent.Parent.Parent.Death:Play()
script.Parent.Visible = true
end

Answer this question