How to do a "Time Left" leaderstat?

What do you want to achieve?
I want to make a “Time Left” leaderboard that is at 30 when the player join then do -1 every second.

What is the issue?
I don’t understand how leaderstats works, so I don’t know how to do that.

What solutions have you tried so far?
Searched on the internet but I found nothing…

Pretty simple! Just make a server script, and connect it to a PlayerAdded Event.
Then, make a folder inside the PlayerObject called leaderstats, then make a intvalue called Time Left. Then just wait a second and loop through all players and decrease their score by one.

game:GetService("Players").PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	local timeLeft = Instance.new("IntValue")
	timeLeft.Name = "Time Left"
	timeLeft.Parent = stats
	timeLeft.Parent = player
end)

while wait(1) do
for i, v in pairs(game.Players:GetChildren()) do
v.leaderstats.timeLeft.Value -= 1
end
end
1 Like

Ok, thanks, I will try that. Have a good day/night!

I just put it into Workspace? Or ServerScriptService?

Edit 1: I tried in ServerScriptService and it doesn’t work.

Edit 2: Workspace doesn’t work.

That is because the person that gave you the code made a slight mistake.

game:GetService("Players").PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	local timeLeft = Instance.new("IntValue")
	timeLeft.Name = "Time Left"
	timeLeft.Parent = stats
	stats.Parent = player
end)

while wait(1) do
    for i, v in pairs(game.Players:GetChildren()) do
    v.leaderstats.timeLeft.Value -= 1
    end
end

All they did was accidentally set the parent of the IntValue twice instead of setting the parent of the folder to the character.

If you want this to work properly, you will have to add more yourself thinking about what the starting time should be, and what the conditions of the countdown would be. MichaelEpicA has only given you an example.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.