If I were to make a level script that when the exp is greater than the Max exp it will go back to 0. Although, i don't like this. Here what I want to happen. Max exp is 1000 and you just got 2000 exp from killing a boss. I want it so that the exp that you got from the boss will subtract from the Max exp. And the remaining exp will be added to exp. If that makes sense. If there is a better way to do this, please tell me. And this is my script on leveling up.
game.Players.PlayerAdded:connect(function(Player) local Data = Instance.new("IntValue",Player) Data.Name = "Data" local XP = Instance.new("IntValue",Data) XP.Name = "XP" XP.Value = 0 local Level = Instance.new("IntValue",Data) Level.Name = "Level" Level.Value = 1 local Tries = Instance.new("IntValue",Data) Tries.Value = 10 Tries.Name = "Tries" local ExCap = Instance.new("IntValue",Data) ExCap.Value = 500 ExCap.Name = "ExCap" XP.Changed:connect(function() XPChange(Player,XP,Level,ExCap) end) end) function XPChange(Player,XP,Level,ExCap) if XP.Value >= ExCap.Value then XP.Value = 0 Level.Value = Level.Value+ 1 ExCap.Value = ExCap.Value * 3 if Level.Value >= 100 then Level.Value = 100 end end end --script where if the Exp is greater than the Max Exp it will resort to 0.--
All that you really need to do is find the overflow and apply that to your experience.
function XPChange(Player, XP, Level, ExCap) if XP.Value >= ExCap.Value then if Level.Value < 100 then Level.Value = Level.Value + 1; ExCap.Value = ExCap.Value * 3; XP.Value = XP.Value-ExCap.Value; -- This one should be done last end end if Level.Value == 100 and XP.Value ~= 0 then XP.Value = 0; end end
So, as an example, if your initial 'ExCap' is 500, and your XP changes to 700, then you will level up and have 200 XP left over.
This also works if you are to level up multiple times. To take the previous example further, if your XP was at 2100 with the initial ExCap of 500, then you would level up twice and be left with 100 XP.
I added the last bit of code so that your XP would stay at 0 once you reached your maximum level. This way, players aren't mislead into believing that their experience is growing when they are actually incapable of leveling up any further.
I hope this helps :P
I would recommend you to change your XpChange function with this function. Try to read it and understand it. It is a really tricky one, but I'm sure you'll understand after reading it over and over. ;D
function XPChange(Player, XP, Level, ExCap) if XP.Value >= ExCap.Value then if Level.Value 100 then Level.Value = 100 else local xpoverflow = XP.Value - maxxp -- This is where it happen. :D XP.Value = xpoverflow Level.Value = Level.Value + 1 ExCap.Value = ExCap.Value * 3 end end end
~WaterFoox (Just posted this and found a much better script and explanation right above mine, lol.)