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

How to make a lvl and xp leaderboard?

Asked by 8 years ago

I have made many attempts on this but it always fails to convert xp into levels (ie if you get 50 xp, it increases your level).

1 answer

Log in to vote
3
Answered by
Uroxus 350 Moderation Voter
8 years ago

It's always a good idea to post the script(s) you've been using so that we can build off of them.


The Leaderboard

To create a basic leaderboard, you'd want to insert the IntValueinto the player when they join. Inside that, you'd then want to add your xp and levels (Providing you want them shown)

game.Players.PlayerAdded:connect(function(plr)
    local leader = Instance.new("IntValue", plr) -- Inserting the instance
    leader.Name = "leaderstats" -- Create the leaderboard by renaming it

    local xp = Instance.new("IntValue", leader) 
    xp.Name = "xp"
    xp.Value = 0 -- Starting value of xp

    local level = Instance.new("IntValue", leader)
    level.Name = "Level"
    level.Value = 0 -- Starting level
end)

That's your basic Leaderboard done.


Upgrading Levels

Now to make the levels change when a specific amount of XP is gained. Providing you already have a system in place which the player will gain xp, this should work (providing you make this a local script and stick it in StarterPack)

local plr = game.Players.LocalPlayer 
plr.leaderstats.xp.Changed:connect(function()
    if plr.leaderstats.xp.Value > 49 then -- If they have more than 49 xp (50 +)
        plr.leaderstats.Level.Value = plr.leaderstats.level.Value +1 -- Add one to their levels
        plr.leaderstats.xp.Value = 0 -- Reset player's xp to 0
    end
end)

That should be your question answered! I have not been able to test any of what I've given you, so no guarantees that it will actually work. If it doesn't please do let me know and I'll try and fix it. If this did work and it answers your question please accept my answer with the button on the right!

Ad

Answer this question