So I've finally got this script down. It's a simple script that levels you up based on if you have the correct experience. Now the problem is:
Say you have 180/200 experience. And then you gain 50 more. I have implemented line 15 to subtract the exp threshold from the experience you have. So when you're at level 2, and gain 50 exp at 180/200, you level up to level 3 and now have 30/300 exp.
Now that line works like a charm, but the problem is: say you have 180/200 exp, and then you gain 500 more exp. The script will subtract 200 when you level up and you will be left with a player who is level 3 with 480/200 exp. I can't figure a way around it. Any help is appreciated. Thanks for reading.
game.Players.PlayerAdded:connect(function(plr)
local stats = Instance.new('IntValue', plr)
stats.Name = 'leaderstats'
experience = Instance.new('IntValue', stats)
experience.Name = 'EXP'
experience.Value = 0
level = Instance.new('IntValue',stats)
level.Name = 'Level'
level.Value = 0
experience.Changed:connect(function()
local required=(level.Value*100)
if experience.Value>=required then
level.Value=level.Value+1
experience.Value=experience.Value-required
end
end)
end)

2 comments
how about you don't give the player 500 xp ;-)
Is that supposed to help?