I’m making an overhead rank system for my game but am running into an issue. The player’s rank is repeatedly set the the first rank, “Scout”, even if they have enough wins for other ranks.
wait(5)
local ServerStorage = game:GetService("ServerStorage")
local player = game.Players:FindFirstChild(script.Parent.Name)
local wins = player:WaitForChild("leaderstats"):WaitForChild("Wins").Value
local gui = player.Character:WaitForChild("Head"):WaitForChild("RankGui").TextLabel
local rankGui = ServerStorage:WaitForChild("RankGui")
local Scout = Color3.new(0.666667, 0.596078, 0.607843)
local Pioneer = Color3.new(0.298039, 0.498039, 0.419608)
local Roamer = Color3.new(1, 0.333333, 0)
local Wanderer = Color3.new(0.333333, 0.333333, 0)
local Pathfinder = Color3.new(0, 0.333333, 0)
local Explorer = Color3.new(1, 1, 0)
local Seeker = Color3.new(1, 0, 1)
local Adventurer = Color3.new(0, 0, 1)
local Vanguard = Color3.new(0, 0.333333, 1)
local Expeditionist = Color3.new(1, 0, 0)
local Apex = Color3.new(1, 1, 0.498039)
local function updateRank()
print("Updating player rank..")
if wins < 1 then
gui.Text = "Scout"
gui.TextColor3 = Scout
elseif wins < 5 then
gui.Text = "Pioneer"
gui.TextColor3 = Pioneer
elseif wins < 10 then
gui.Text = "Roamer"
gui.TextColor3 = Roamer
elseif wins < 15 then
gui.Text = "Wanderer"
gui.TextColor3 = Wanderer
elseif wins < 20 then
gui.Text = "Pathfinder"
gui.TextColor3 = Pathfinder
elseif wins < 25 then
gui.Text = "Explorer"
gui.TextColor3 = Explorer
elseif wins < 30 then
gui.Text = "Seeker"
gui.TextColor3 = Seeker
elseif wins < 35 then
gui.Text = "Adventurer"
gui.TextColor3 = Adventurer
elseif wins < 40 then
gui.Text = "Vanguard"
gui.TextColor3 = Vanguard
elseif wins < 45 then
gui.Text = "Expeditionist"
gui.TextColor3 = Expeditionist
else
gui.Text = "Apex"
gui.TextColor3 = Apex
end
end
wait(2)
updateRank()
player:WaitForChild("leaderstats"):WaitForChild("Wins").Changed:Connect(function()
updateRank()
end)
Well no not really. It would give an error of something like: attempt to compare nil with number
Although we have no idea what wins is set to. It could be a leaderstats value or just something else. But this seems to be a LocalScript so I doubt that
Are you sure whatever is updating Wins is on the server-side? If it’s being set by another client then it might not work (I don’t really know how leadrerstats work, so excuse me if I am incorrect)
If I am guessing, you already defined the wins variables value meaning you only have a static non changing number (if I can explain that well).
Remove .Value and on obtain it when you call the function.
Also for good practices, pass in the wins argument.
wait(5)
local ServerStorage = game:GetService("ServerStorage")
local player = game.Players:FindFirstChild(script.Parent.Name)
local win = player:WaitForChild("leaderstats"):WaitForChild("Wins") -- .Value removed
local gui = player.Character:WaitForChild("Head"):WaitForChild("RankGui").TextLabel
local rankGui = ServerStorage:WaitForChild("RankGui")
local Scout = Color3.new(0.666667, 0.596078, 0.607843)
local Pioneer = Color3.new(0.298039, 0.498039, 0.419608)
local Roamer = Color3.new(1, 0.333333, 0)
local Wanderer = Color3.new(0.333333, 0.333333, 0)
local Pathfinder = Color3.new(0, 0.333333, 0)
local Explorer = Color3.new(1, 1, 0)
local Seeker = Color3.new(1, 0, 1)
local Adventurer = Color3.new(0, 0, 1)
local Vanguard = Color3.new(0, 0.333333, 1)
local Expeditionist = Color3.new(1, 0, 0)
local Apex = Color3.new(1, 1, 0.498039)
local function updateRank(wins) -- wins argument added
print("Updating player rank..")
if wins < 1 then
gui.Text = "Scout"
gui.TextColor3 = Scout
elseif wins < 5 then
gui.Text = "Pioneer"
gui.TextColor3 = Pioneer
elseif wins < 10 then
gui.Text = "Roamer"
gui.TextColor3 = Roamer
elseif wins < 15 then
gui.Text = "Wanderer"
gui.TextColor3 = Wanderer
elseif wins < 20 then
gui.Text = "Pathfinder"
gui.TextColor3 = Pathfinder
elseif wins < 25 then
gui.Text = "Explorer"
gui.TextColor3 = Explorer
elseif wins < 30 then
gui.Text = "Seeker"
gui.TextColor3 = Seeker
elseif wins < 35 then
gui.Text = "Adventurer"
gui.TextColor3 = Adventurer
elseif wins < 40 then
gui.Text = "Vanguard"
gui.TextColor3 = Vanguard
elseif wins < 45 then
gui.Text = "Expeditionist"
gui.TextColor3 = Expeditionist
else
gui.Text = "Apex"
gui.TextColor3 = Apex
end
end
wait(2)
updateRank(win.Value)
player:WaitForChild("leaderstats"):WaitForChild("Wins").Changed:Connect(function()
updateRank(win.Value)
end)