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

My ranking system doesn't work (test), any answers on why?

Asked by 5 years ago
Edited 5 years ago
game.Players.PlayerAdded:Connect(function(plr)

    local leaderstats = Instance.new('Folder',plr)
    leaderstats.Name = 'leaderstats'

    local rank = Instance.new('StringValue',leaderstats)
    rank.Name = 'Rank'
    rank.Value = 'Private'

    local xp = Instance.new('IntValue',leaderstats)
    xp.Name = 'XP'
    xp.Value = 0

    while wait(3) do

        xp.Value = xp.Value + 1

    end

    if (xp.Value >= 10) then

        rank.Value = 'Corporal'

    end

end)
0
Your script will never hit line 20 and below, as wait(3) on line 14 will always be true, causing an infinite loop. TheIndigoNight 40 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

Pretty easy answer. Change everything underneath xp.Value = 0 to (explanation underneath script):

while wait(3) do
    xp.Value = xp.Value + 1 -- Random note but Lua seriously needs to add += or something like that
    if xp.Value >= 10 then
        rank.Value = "Corporal"
    end
end

What we do here is check every time the loop runs if xp.Value is greater than or equal to 10. If it is, we rank up the player. We then continue to increase the player's xp.

Ad

Answer this question