I'm trying to make a level-up script. I got the leader-board to work, but the problem is that my equation doesn't work. You'll see what I mean
local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild('leaderstats')
local level = leaderstats:WaitForChild('Level')
local xp = player:WaitForChild('EXP')
level.Changed:connect(function()
local n = level.Value
if xp.Value > 50*(n^2-n+2) then
level.Value = level.Value+1
end
end)
So the pattern for how much experience you need to go from level 1 --> 2 --> 3 --> 4 --> 5 --> 6 would be 100, 200, 400, 700, 1100, 1600. (It adds 100 exp from one term to the next) Here's the leader-stats script which is causing me confusion
game.Players.PlayerAdded:connect(function(plr)
local stats = Instance.new('IntValue', plr)
stats.Name = 'leaderstats'
local experience = Instance.new('IntValue', stats)
experience.Name = 'EXP'
experience.Value = 0
local level = Instance.new('IntValue',stats)
level.Name = 'Level'
level.Value = 1
experience.Changed:connect(function()
local q = experience.Value
level.Value = math.floor((50*(q^2-q+2)))
end)
end)
EDIT: I got the script backwards. Now when I have 1 exp, I'm level 100, with 2 exp, I'm level 200, 3 exp I'm level 400 and so on. I can't figure out a way to reverse this even though I know the problem lies in line 13 of the second script

1 comment
I think your < sign should be a > sign, and you should also reset the EXP value to 0 when you increase the level. I'm not entirely sure what your workspace userdata setup is, but I feel like the listening event should be waiting for xp to change, not level.