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

Leveling system won't work properly?

Asked by
jetape 9
4 years ago

I've been trying to create a leveling system using String Values. Basically, everytime you level up, you're given a new rank. E.g, Junior Manager, Manager, senior manager, etc.

game.Players.PlayerAdded:Connect(function(player)
    local rank = Instance.new('StringValue', player)
    rank.Name = 'Level'
    rank.Value = 'Cadet'
    rank.Parent = player

    local exp = Instance.new('IntValue', rank)
    exp.Name = 'Loyalty'
    exp.Value = 0

    local maxExp = Instance.new('IntValue', rank)
    maxExp.Name = "Max"
    maxExp.Value = 10


    exp.Changed:Connect(function(val)
        if exp.Value == 15 then
            rank.Value = 'Private First Class'
            exp.Value = 0
            maxExp.Value = 20
        elseif
         exp.Value == 10 then
            rank.Value = 'Private'
            exp.Value = 0
            maxExp.Value = 15
        end
    end)
end)

Essentially, the problem is that the value changes to 15 like the bottom part of code asks, but it resets everytime when it reaches 10 instead of 15 like I want it to. Visual of error. Because of this, the text label will not change to say "Private First Class". I receive no errors in the output, and I'm completely stumped, any help would be appreciated.

0
hey buddy!, try usog exp.GetPropertyChanedSignal("Value") instead of exp.Changed! xXKatchaXx 0 — 4y
0
That just breaks the script entirely jetape 9 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

It looks like you don't have rank checking in your script and only just the value checker. To fix that, you can simply do :

exp.Changed:Connect(function(val)
        if exp.Value == 15 and rank.Value ~= "Private First Class" then -- It checks whether the exp value is 15 and rank value is not equal to Private First Class
            rank.Value = 'Private First Class'
            exp.Value = 0
            maxExp.Value = 20
        elseif
         exp.Value == 10 and rank.Value ~= "Private" then -- It checks whether the exp value is 10 and rank value is not Private
            rank.Value = 'Private'
            exp.Value = 0
            maxExp.Value = 15
        end
end)

Lemme know if it helps!

0
Absolute saviour, thanks so much! jetape 9 — 4y
Ad

Answer this question