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

How can i play a sound if a player Dies?

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?

2 comments

0

Why the tag Trigonometry?

0

It was supposed to be Event but i got confused

1 answer

✓ Accepted answer

Very simple question.

I'll explain how this works in the script.

sound  =  game.Workspace.sound -- The audio


game.Players.PlayerAdded:connect(function(player) -- When a player enters. The parameter represents the player who entered
	player.CharacterAdded:connect(function(char) -- The players character (Which contains humanoid)
			char.Humanoid.Died:connect(function(died) -- When the player dies
		soundClone = sound:Clone() -- Creates a variable of Cloning the sound
               soundClone.Parent = player.PlayerGui -- Sets the parent of the cloned sound to the players Gui, so only the player who died will hear it
               soundClone:Play() -- Plays the sound
		    end
		end)
	end)
end)

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

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