Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a lvl and xp leaderboard?

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

✓ Accepted answer

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 IntValue into 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!

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