Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a leaderboard that updates as time goes on? [closed]

Asked by 3 years ago

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")

0
This is not a request! pugguy1000 3 — 3y

Closed as Not Constructive by RazzyPlayz, namespace25, ScuffedAI, and imKirda

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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!

1
I like how you say that this isn't a request site yet you still fullfil his request. ScuffedAI 435 — 3y
0
Yep, I always like to help out, though, it's always good to let people know the rules as well. RazzyPlayz 497 — 3y
Ad