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

How can i play a sound if a player Dies?

Asked by 10 years ago

I know how to play sounds OnEnter but this is what I don't get How can I play a sound when a player dies?

0
Why the tag Trigonometry? Tesouro 407 — 10y
0
It was supposed to be Event but i got confused digitalzer3 123 — 10y

1 answer

Log in to vote
1
Answered by 10 years ago

Very simple question.

I'll explain how this works in the script.

01sound  =  game.Workspace.sound -- The audio
02 
03 
04game.Players.PlayerAdded:connect(function(player) -- When a player enters. The parameter represents the player who entered
05    player.CharacterAdded:connect(function(char) -- The players character (Which contains humanoid)
06            char.Humanoid.Died:connect(function(died) -- When the player dies
07        soundClone = sound:Clone() -- Creates a variable of Cloning the sound
08               soundClone.Parent = player.PlayerGui -- Sets the parent of the cloned sound to the players Gui, so only the player who died will hear it
09               soundClone:Play() -- Plays the sound
10            end
11        end)
12    end)
13end)

If you want everyone to hear it just type sound:Play() Instead of cloning it.

Ad

Answer this question