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

How do i make something happen if a Player Dies?

Im trying to make a script that sets a BoolValue to True but i dont know how to do that! Please Help!

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model", player)
    leaderstats.Name = "leaderstats"
    local wins = Instance.new("IntValue", leaderstats)
    wins.Name = "Wins"
    wins.Value = 0
    local dead = Instance.new("BoolValue", player)
    dead.Name = "Died"
    dead.Value = false
end)


while wait(120) do 
    for _,Player in pairs(game.Players:GetPlayers()) do
        if Player.Died.Value == false then
            Player.leaderstats.Wins.Value = Player.leaderstats.Wins.Value +1

					else
	
			game.Players.Player.Died.Value = false
	
        end
    end
end

local player = game.Players.LocalPlayer

game.Workspace.player.Humanoid.Changed:connect(function()
    if game.Workspace.player.Humanoid.Health == 0 then
        Player.Died.Value = true
    end
end)

1 comment

0

Player.CharacterRemoving fires right after someone dies.

2 answers

✓ Accepted answer

Died() is an event :P Check this

2 comments

0

Yes, but thats of the humanoid. CharacterRemoving is more direct.

0

GoldenP, but not everyone Deletes the Body... some people leave the Body as to scare people in Horror Games, like Darkness... Character = Model of Player... so if it's not Deleted then, the function isn't fired, cos the Body is still there, but yeah, it is if ur doing Default Death (Which I don't like, and don't recommend)

player = game.Players.LocalPlayer.Name

game.Workspace.player.Humanoid.Changed:connect(function()
	if game.Workspace.player.Humanoid.Health == 0 then
		boolvalue = true
	end
end)

Something like this I believe.

1 comment

0

tkdrocks2017 i tried it in this but it wont work =( did i put it in wrong? game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model", player) leaderstats.Name = "leaderstats" local wins = Instance.new("IntValue", leaderstats) wins.Name = "Wins" wins.Value = 0 local dead = Instance.new("BoolValue", player) dead.Name = "Died" dead.Valu

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