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

I'm making a XP system but it keeps saying something is wrong help?

Asked by 4 years ago

So this is my code for my game

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local EXP = Instance.new("NumberValue", leaderstats)
    EXP.Name = "EXP"

    local Lvl = Instance.new("NumberValue", leaderstats)
    Lvl.Name = "Level"
    Lvl.Value = 1

    local MaxEXP = 100 * (Lvl.Value / 2)

    game.ServerStorage.GiveExp.Event:Connect(function(amount,plr)
        if player.Name == plr.Name then
            EXP.Value = EXP.Value + amount
        end
    end)
    EXP:GetPropertyChangedSignal("Value"):Connect(function()
        if EXP.Value >= MaxEXP.Value then
            EXP.Value - MaxEXP.Value
            Lvl.Value = Lvl.Value + 1
        end
    end)
end)

and its saying this segment is wrong

EXP.Value - MaxEXP.Value

I don't really understand why it's doing that and how to fix it

1 answer

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago

This is because you’re performing a blank arithmetic. To actively modify a state, you have to apply the = assign operator.

EXP.Value = (EXP.Value - MaxEXP.Value)
Ad

Answer this question