Updating Leaderboard Display

I have this death detector that helps with subtracting a life each time a player dies. The problem is that the leaderboard is not updating after the player dies, but the variable does update.

LocalScript in StarterChararacterScripts:

local player = game.Players.LocalPlayer
local character = player.Character

character:WaitForChild("Humanoid").Died:Connect(function()
	local lives = player.leaderstats.Lives.Value 
	lives = lives - 1
	print("lives: " .. lives) -- prints out "2" 
end)

Script in ServerScriptService:

local function onPlayerJoin(player)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local lives = Instance.new("IntValue")
	lives.Name = "Lives"
	lives.Parent = leaderstats
	lives.Value = 3

end

game.Players.PlayerAdded:Connect(onPlayerJoin)

OUTPUT:

13:32:43.435 - lives: 2

But on the leaderboard in-game, it still displays I have 3 lives left.

Where you did “local Lives = player.leaderstats.Lives.Value” just use player.leaderstats.Lives
then lives.Value = lives.Value - 1

1 Like

Change this :

character:WaitForChild("Humanoid").Died:Connect(function()
	local lives = player.leaderstats.Lives.Value 
	lives = lives - 1
	print("lives: " .. lives) -- prints out "2" 
end)

to this :

character:WaitForChild("Humanoid").Died:Connect(function()
	local lives = player.leaderstats.Lives 
	lives.Value = lives.Value - 1
	print("lives: " .. lives) -- prints out "2" 
end)

Because before when you wrote lives = lives -1, you were just subtracting one from the value stored in the variable and printing that result, not changing the value in the leaderstats itself.