Making a death counter

I want to create a leaderboard stat and when a player dies there death counter goes up one. its a make fun of player kind of thing in my game

This is most likely not the place to post this. Post it in #help-and-feedback:game-design-support instead. Thank you

Create a counter where if the player’s health is 0 then it would add 1 to the death value.

1 Like
game.Players.PlayerAdded:Connect(function(plr)
    local ls = Instance.new("Folder", plr)
    ls.Name = "leaderstats"

    local deaths = Instance.new("IntValue", ls)
    deaths.Name = "Deaths"

    plr.CharacterAdded:Connect(function()
        repeat wait() until plr.Character ~= nil
        local char = plr.Character
        local hum = char:WaitForChild("Humanoid")
        
        hum.Died:Connect(function()
            deaths.Value += 1
        end)
    end)
end)
2 Likes

sorry im new to the dev forum and im still not sure how to navigate very well but isent this a scripting thing?

like @OIogist has suggested, you would have to do something along the lines of that to create a death leaderboard.

game.Players.PlayerAdded:Connect(function(player) 

A function that fires when a player enter the game.

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

We’re creating a folder named leaderstats which has all of our leaderboard values and ect. This folder will be parented to the player.

local deaths = Instance.new("IntValue")
deaths.Name = "Deaths"
deaths.Value = 0
deaths.Parent = leaderstats

Now we’re creating our death “IntValue” to parent to our leaderstats folder. This will be set to 0 as a default.

character:WaitForChild("Humanoid").Died:Connect(function()

This event will run when the humanoid has died

player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value + 1

This gives the player 1 more death in their leaderstats.

If you want to go ahead and save the data, you should DataStores and experiment with them. That is on your part to do. You can learn more about them here

1 Like

Yes but this place is for where someone has a scripting problem, and they ask for help to fix it. #help-and-feedback:game-design-support would be for questions about how to do a whole thing in a game, or ‘how is the game right now.’

CharacterAdded fires when the player’s character is added, so there is no need to use a repeat loop to wait for the character to exist. Instead use the character parameter of CharacterAdded:

game:GetService("Players").PlayerAdded:Connect(function(Plr)
	local leaderstats = Instance.new("Folder", Plr)
	leaderstats.Name = "leaderstats"
	
	local deaths = Instance.new("IntValue", leaderstats)
	deaths.Name = "Deaths"
	
	Plr.CharacterAdded:Connect(function(Char)
		local humanoid = Char:WaitForChild("Humanoid")
		humanoid.Died:Connect(function()
			deaths.Value = deaths.Value + 1
		end)
	end)
end)
2 Likes