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

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

Asked by 8 years ago
Edited 8 years ago

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:

01local player = script.Parent.Parent.Parent.Parent.Parent -- this is not the problem
02local xp = player.leaderstats.XP
03local lvl = player.leaderstats.Level
04if xp == 200 then
05    xp = xp - 200
06    lvl = lvl + 1
07end
08if xp > 200 then
09    xp = xp - 200
10    lvl = lvl + 1
11end

1 answer

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

Try something like this:

1exp = 0
2level = 1
3maxexp = level*10
4function levelupdate()
5    if exp>maxexp then
6        level = level + 1
7        maxexp = level*10
8    end
9end

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.

Ad

Answer this question