How do I make a rank system?
type I opened a total of boxes there I get a rank
I’ll try to explain it quickly.
I wanted to make a system of rank with style these simulators, example you collected a total of blocks ai you receive a new rank, I really wanted to know how I do it, I already saw several tutorials is not able to find one explaining how to do, thank you
•It is yes and my first time using the dev forum, sorry guys
This is actually quite easy.
The way I would do this would be having a while wait() do loop
Inside of the loop it would check if your stats are greater than one value, let’s say “Fresh Unboxer” (or 10) and less than another value “Box Cutter” (25) if it is then it would set your overhead text to Fresh Unboxer.
Another way you can do it is easier to use. I wrote simple code if it’s just on the leaderboard. Script:
local functions = {}
functions.Create = function(p)
if p then
if p:IsA("Player") then
local ls = Instance.new("Folder", p)
ls.Name = "leaderstats"
local iv = Instance.new("IntValue", ls)
iv.Name = "Boxes Unboxed"
iv.Value = 0
local rn = Instance.new("StringValue", ls)
rn.Name = "Rank"
rn.Value = "Loading"
end
end
end
game.Players.PlayerAdded:Connect(function(p)
functions.Create(p)
end)
local Ranks = {
["Noob Unboxer"] = 0,
["Good Unboxer"] = 10,
["Great Unboxer"] = 25
}
game:GetService("RunService").Heartbeat:Connect(function()
for _,v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("leaderstats") then
local ls = v:FindFirstChild("leaderstats")
if ls:FindFirstChild("Boxes Unboxed") and ls:FindFirstChild("Rank") then
local bu = ls:FindFirstChild("Boxes Unboxed")
local r = ls:FindFirstChild("Rank")
spawn(function()
for k,v in next, Ranks do
print(k)
if bu.Value >= v then
r.Value = k
end
end
end)
end
end
end
end)
wait(5) --remove this wait 5 and things under it
for i = 1,25 do
for _,v in pairs(game.Players:GetPlayers()) do
v:WaitForChild("leaderstats")["Boxes Unboxed"].Value = i
end
wait(.3)
end
local Ranks = { -- Store them in ascending order!
{Name = "Noob Unboxer", Color = Color3.fromRGB(--[[colors here]]), Score = 0},
{Name = "Fresh Unboxer", Color = Color3.fromRGB(), Score = 10},
{Name = "Box Cutter", Color = Color3.fromRGB(), Score = 25},
-- the other ones
}
local function GetRank(score)
for i,rank in ipairs(Ranks) do
if score < rank.Score then
return Ranks[i-1]
end
end
end
Also, I wouldn’t do this every single heartbeat or wait(), that is definitely too much work for just an overhead rank. I would probably let it update every 3-5 seconds, 10 would work even:
while wait(5) do
local rank = GetRank(player.leaderstats.BoxesUnboxed.Value)
RankGuiLabel.Text = rank.Name
RankGuiLabel.TextColor3 = rank.Color
end
In fact, I would hook this to BoxesUnboxed'sChanged event just to guarantee consistency:
game.Players.PlayerAdded:Connect(function(player)
--do something with `player`
end)
You have to create the leaderstats Folder that goes inside the player and the BoxesUnboxed IntValue that goes inside leaderstats. Note that this will create a leaderboard that all players can view from the player roster:
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local BoxesUnboxed = Instance.new("IntValue")
BoxesUnboxed.Name = "BoxesUnboxed"
BoxesUnboxed.Parent = leaderstats
leaderstats.Parent = player
Color3.fromRGB accepts three values for red, green, and blue, each ranging from 0 to 255, as the dev wiki would say.
Your while loop is malformed, ditch the loop as a whole:
RankGuiLabel has to be defined, just make a StarterCharacter in StarterPlayer with this overhead gui already created in it, using a BillboardGui offsetted a few studs upward, then you have to navigate to it from player.Character and define it from there:
local character = player.Character
if character then
--Change this to where the gui is in the character
local gui = character.BillboardGui
--Change this to where the label is in the gui
local RankGuiLabel = gui.RankGuiLabel
--change RankGuiLabel's properties
end
Note that nothing here is in order or complete, you will need to do some work on your part to fit the pieces together. Try looking through the dev wiki for more tutorials or answers to your questions, and if you can’t find it there, you can ask here.
Having pointless background loops is bad code. You should instead only be updating the information based on if the value changes (step in, GetPropertyChangedSignal). An example would be within what @goldenstein64 posted.