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

How do you make a level up script that always levels you up based on a certain amount of experience?

I am making a game. I want you to level up every time you get to or surpass 200 experience. The only time it works is on level 2. Before level 2, you level up before getting to 200 experience. After level 2, it takes more than 200 experience. I have tried a bunch of different scripts. They all look a little like this:

local player = script.Parent.Parent.Parent.Parent.Parent -- this is not the problem
local xp = player.leaderstats.XP
local lvl = player.leaderstats.Level
if xp == 200 then
	xp = xp - 200
	lvl = lvl + 1
end
if xp > 200 then
	xp = xp - 200
	lvl = lvl + 1
end

1 answer

✓ Accepted answer

Try something like this:

exp = 0
level = 1
maxexp = level*10
function levelupdate()
	if exp>maxexp then
		level = level + 1
		maxexp = level*10
	end
end

and execute it when the player gains exp with "levelupdate()"

this way every time a player gains exp, it will check if exp is enough to level up, and if the player does have enough exp then the players level, and maxexp will update.

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