I have tried making a ranking system based on a players stat but this does not work properly.
When I test this in game I have 30k SP and should have the Master
rank yet I still have the rank after that which requires 50k
This is the code :
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Modules = ReplicatedStorage:WaitForChild("Modules") local Ranks = require(Modules:WaitForChild("Ranks")) local CS = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService")) local UpdateRank = function(Speaker, Player) local Leaderstats = Player:WaitForChild("leaderstats") local SP = Leaderstats:WaitForChild("SP") for key, value in pairs(Ranks) do local RequiredSP = value.RequiredSP local Color = value.Color local Name = key if SP.Value <= RequiredSP then local Character = Player.Character or Player.CharacterAppearanceLoaded:Wait() local Humanoid = Character:WaitForChild("Humanoid") local Head = Character:WaitForChild("Head") local Rank = Head:WaitForChild("Rank") local Label = Rank:WaitForChild("Label") Label.Text = Name Label.TextColor3 = Color Speaker:SetExtraData("Tags",{{TagText = Name, TagColor = Color}}) break end end end CS.SpeakerAdded:Connect(function(Speaker) local Player Speaker = CS:GetSpeaker(Speaker) Player = Speaker:GetPlayer() if Player then local Leaderstats = Player:WaitForChild("leaderstats") local SP = Leaderstats:WaitForChild("SP") UpdateRank(Speaker, Player) SP:GetPropertyChangedSignal("Value"):Connect(function() UpdateRank(Speaker, Player) end) Player.CharacterAppearanceLoaded:Connect(function(Character) UpdateRank(Speaker, Player) end) end end)
And here is the ranks module :
return { ["Noob"] = { RequiredSP = 0, Color = Color3.fromRGB(231, 234, 18) }, ["Rookie"] = { RequiredSP = 100, Color = Color3.fromRGB(115, 115, 115) }, ["Average"] = { RequiredSP = 1000, Color = Color3.fromRGB(218, 0, 3) }, ["Expert"] = { RequiredSP = 5000, Color = Color3.fromRGB(10, 184, 236) }, ["Grinder"] = { RequiredSP = 10000, Color = Color3.fromRGB(18, 188, 72) }, ["Master"] = { RequiredSP = 25000, Color = Color3.fromRGB(68, 177, 136) }, ["Legend"] = { RequiredSP = 50000, Color = Color3.fromRGB(255, 255, 0) }, ["Heavy Grinder"] = { RequiredSP = 100000, Color = Color3.fromRGB(54, 54, 54) }, ["Unstoppable"] = { RequiredSP = 250000, Color = Color3.fromRGB(115, 0, 1) }, ["Hacker"] = { RequiredSP = 1000000, Color = Color3.fromRGB(0, 255, 0) }, ["Amazingly Good"] = { RequiredSP = 5000000, Color = Color3.fromRGB(158, 0, 197) }, [":)"] = { RequiredSP = 10000000, Color = Color3.fromRGB(0, 0, 0) }, }
Thank you for taking your time to read this question.
You did a little mistake on line 13 (outside of module script)
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Modules = ReplicatedStorage:WaitForChild("Modules") local Ranks = require(Modules:WaitForChild("Ranks")) local CS = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService")) local UpdateRank = function(Speaker, Player) local Leaderstats = Player:WaitForChild("leaderstats") local SP = Leaderstats:WaitForChild("SP") for key, value in pairs(Ranks) do local RequiredSP = value.RequiredSP local Color = value.Color local Name = key if SP.Value >= RequiredSP then -- right here local Character = Player.Character or Player.CharacterAppearanceLoaded:Wait() local Humanoid = Character:WaitForChild("Humanoid") local Head = Character:WaitForChild("Head") local Rank = Head:WaitForChild("Rank") local Label = Rank:WaitForChild("Label") Label.Text = Name Label.TextColor3 = Color Speaker:SetExtraData("Tags",{{TagText = Name, TagColor = Color}}) break end end end CS.SpeakerAdded:Connect(function(Speaker) local Player Speaker = CS:GetSpeaker(Speaker) Player = Speaker:GetPlayer() if Player then local Leaderstats = Player:WaitForChild("leaderstats") local SP = Leaderstats:WaitForChild("SP") UpdateRank(Speaker, Player) SP:GetPropertyChangedSignal("Value"):Connect(function() UpdateRank(Speaker, Player) end) Player.CharacterAppearanceLoaded:Connect(function(Character) UpdateRank(Speaker, Player) end) end end)
You were checking if requiredSP is higher or equal to SP