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

How to make XP carry over to another level?

Asked by
soutpansa 120
5 years ago

My level system doesn't carry over XP if you get more than you need. If you need 1000 XP to level up, but get 1500 then it won't make the 500 count towards the next level. I was thinking maybe if the XP value is greater than what you need to level up it can store it as a value and then add the value to the player's XP after they level up? Not really sure how to do this though. Here's my level system:

XP.Changed:Connect(function()
    if XP.Value >= Level.Value * 20 then
        Stats.XP.Value = 0 
        Player.Character.Humanoid.Health = Player.Character.Humanoid.Health + 100000
        Stats.Level.Value = Stats.Level.Value + 1
        Stats.StatPoints.Value = Stats.StatPoints.Value + 3
        Player.Character.UpperTorso.LevelUp:Play()
        local Particle = game.ReplicatedStorage.LevelParticle:Clone()
        Particle.Parent = Player.Character.UpperTorso
        Particle.delete.Disabled = false
    end
end)

thanks for reading

0
Could you not just change line3 to “Stats.xp.Value = xp.Value - Level.Value * 20” ? ABK2017 406 — 5y

2 answers

Log in to vote
1
Answered by
Nosteal 50
5 years ago

Replace

Stats.XP.Value = 0

^This always sets the value XP to 0

with

Stats.XP.Value = Stats.XP.Value - (Level.Value * 20)

^This subtracts the level multiplied by 20 from XP

Ad
Log in to vote
0
Answered by
gullet 471 Moderation Voter
5 years ago

You can use modulo % to get the remainder in division

local xp_per_level = 100
local total_xp = 230
local xp = total_xp % xp_per_level -- 30

Answer this question