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

Exp game mechanic not working?

Asked by 8 years ago

I am wanting the rank the players up based on their Exp. for whatever reason, if the RankVal is changed they are automatically made an Elder. It won't even change ranks depending on the Exp. No errors in the output.

local player = game.Players.LocalPlayer

local ranks = {
    [1] = "Newbie"; -- 0
    [2] = "Member"; -- 100
    [3] = "Forager"; -- 300
    [4] = "Watcher"; -- 600
    [5] = "Mason"; -- 1200
    [6] = "Warrior"; -- 2400
    [7] = "Runner"; -- 4800
    [8] = "Elder"; -- 9600
};



repeat wait() until player.Character

player.leaderstats.RankVal.Changed:connect(function()
    print("Works")
    if player.leaderstats.Exp.Value <= 100 and player.leaderstats.Exp.Value > 300 then player.leaderstats.RankVal.Value = 2
    elseif player.leaderstats.Exp.Value <= 300 and player.leaderstats.Exp.Value > 600 then player.leaderstats.RankVal.Value = 3
    elseif player.leaderstats.Exp.Value <= 600 and player.leaderstats.Exp.Value > 1200 then player.leaderstats.RankVal.Value = 4
    elseif player.leaderstats.Exp.Value <= 1200 and player.leaderstats.Exp.Value > 2400 then player.leaderstats.RankVal.Value = 5
    elseif player.leaderstats.Exp.Value <= 2400 and player.leaderstats.Exp.Value > 4800 then player.leaderstats.RankVal.Value = 6
    elseif player.leaderstats.Exp.Value <= 4800 and player.leaderstats.Exp.Value > 9600 then player.leaderstats.RankVal.Value = 7
    elseif player.leaderstats.Exp.Value <= 9600 then player.leaderstats.RankVal.Value = 8
    end
end)
0
Lol, you should have used a variable for the Exp. User#11440 120 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago

You mixed up your greater than and less than signs

All I did was switch every single > to < and every single < to >. Remember, This > means greater than and < means less than. Think of it like stating a fact. 5 is greater than 3, so 5 > 3. This might not help. But find a way to remember.

I also used variables to make the code more simple. When referencing something for more than once or twice, use a variable.

Here's the code.

local player = game.Players.LocalPlayer
local RankVal = player.leaderstats.RankVal

local ranks = {
    [1] = "Newbie"; -- 0
    [2] = "Member"; -- 100
    [3] = "Forager"; -- 300
    [4] = "Watcher"; -- 600
    [5] = "Mason"; -- 1200
    [6] = "Warrior"; -- 2400
    [7] = "Runner"; -- 4800
    [8] = "Elder"; -- 9600
};



repeat wait() until player.Character

player.leaderstats.RankVal.Changed:connect(function()
    local Exp = player.leaderstats.Exp
    print("Works")
    if Exp.Value >= 100 and Exp.Value < 300 then RankVal.Value = 2
    elseif Exp.Value >= 300 and Exp.Value < 600 then RankVal.Value = 3
    elseif Exp.Value >= 600 and Exp.Value < 1200 then RankVal.Value = 4
    elseif Exp.Value >= 1200 and Exp.Value < 2400 then RankVal.Value = 5
    elseif Exp.Value >= 2400 and Exp.Value < 4800 then RankVal.Value = 6
    elseif Exp.Value >= 4800 and Value < 9600 then RankVal.Value = 7
    elseif Exp.Value >= 9600 then RankVal.Value = 8
    end
end)

Hope that helped! Good Luck!

Ad
Log in to vote
0
Answered by 8 years ago
local player = game.Players.LocalPlayer

local ranks = {
    one = "Newbie"; -- 0
    two = "Member"; -- 100
    three = "Forager"; -- 300
    four = "Watcher"; -- 600
    five = "Mason"; -- 1200
    six = "Warrior"; -- 2400
    seven = "Runner"; -- 4800
    eight = "Elder"; -- 9600
};



repeat wait() until player.Character

player.leaderstats.RankVal.Changed:connect(function()
    print("Works")
    if player.leaderstats.Exp.Value <= 100 and player.leaderstats.Exp.Value > 300 then player.leaderstats.RankVal.Value = ranks.two
    elseif player.leaderstats.Exp.Value <= 300 and player.leaderstats.Exp.Value > 600 then player.leaderstats.RankVal.Value = ranks.three
    elseif player.leaderstats.Exp.Value <= 600 and player.leaderstats.Exp.Value > 1200 then player.leaderstats.RankVal.Value = ranks.four
    elseif player.leaderstats.Exp.Value <= 1200 and player.leaderstats.Exp.Value > 2400 then player.leaderstats.RankVal.Value = ranks.five
    elseif player.leaderstats.Exp.Value <= 2400 and player.leaderstats.Exp.Value > 4800 then player.leaderstats.RankVal.Value = ranks.six
    elseif player.leaderstats.Exp.Value <= 4800 and player.leaderstats.Exp.Value > 9600 then player.leaderstats.RankVal.Value = ranks.seven
    elseif player.leaderstats.Exp.Value <= 9600 then player.leaderstats.RankVal.Value = ranks.eight
    end
end)

Answer this question