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 a leaderboard that updates as time goes on?

Hi there. I need to make a leaderboard which goes up by 1 points, say, every5 seconds the player doesn't die. I also need the learderboard to reset when the player dies. Thanks you!

(Also, the leaderboard is called "Points")

1 comment

0

This is not a request!

1 answer

✓ Accepted answer

Hello.

Before this question gets answered, please note that ScriptingHelpers is NOT a request site! ScriptingHelpers is only here for answering questions or issues you have with your code.

If you do request in ScriptingHelpers, your post will most likely be taken down. Furthermore, I suggest you giving the system a try as well, it gives you practice!

Anyway, with that out of the way, you can simply add a while loop to the leaderstats code, that updates the Points value by 1 every 5 seconds. This will keep updating the Points every time with addition.

You can then use the Humanoid.Died function to determine when the Player dies, and we can then reset the points to 0.

Here's an example:

local Players = game:GetService("Players")
local UpdatePoints = false

Players.PlayerAdded:Connect(function(Player)	
	Player.CharacterAdded:Connect(function(Character)
		UpdatePoints = true

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

		local Points = Instance.new("IntValue")
		Points.Name = "Points"
		Points.Parent = Leaderstats
		
		Player.leaderstats.Points.Value = 0
		
		local Humanoid = Character.Humanoid
		Humanoid.Died:Connect(function()
			UpdatePoints = false
			Player.leaderstats.Points.Value = 0
		end)

		while (UpdatePoints) do
			wait(5)
			Player.leaderstats.Points.Value += 1
			if not (UpdatePoints) then
				break
			end
		end
	end)
end)

Hope this helps!

2 comments

1

I like how you say that this isn't a request site yet you still fullfil his request.

0

Yep, I always like to help out, though, it's always good to let people know the rules as well.

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