Create a BillboardGui with a TextLabel, modify its properties to your liking, and put it in ServerStorage. Then, in a server script connect a function to the PlayerAdded event which clones the BillboardGui and parents it the the player’s head. Additionally, set the TextLabel’s text to the player’s leaderstats value. Then, in the script(s) where you change the values of the leaderstats, whenever you change the leaderstats, also change the TextLabels’s text to the value of the leaderstat or something like “Pro” if the leaderstat is greater than a certain value.
Also, instead of going into the leaderstats scripts, you could just connect a function to [leaderstat]:GetPropertyChangedSignal(“Value”) and set the leaderstat value to the TextLabel.
In the BillboardGui, change the ExtentsOffset property to 0,5,0 (So the nametag appears right above the player’s head. If it was set to 0,0,0, the nametag would appear right at the player’s head.)
Change the TextLabelText property to “Noob” ( The nametag will be ‘Noob’ when the player joins the game for the first time, but will change as the player reach more stages. You can not do that if you want. )
In the TextLabel, change the BackgroundTransparency to 1 and enable the property TextScaled
Note: These properties changes are my own options. If you don’t like them, you can change them if you want.
Now, customize the TextLabel in your own way!
Add a Script in ServerScriptService
Put that code in it:
--Variables
local billboard = game.ServerStorage:WaitForChild("BillboardGui") -- Waits for the BillboardGui to appear in ServerStorage
local PlayerBillboard = billboard:Clone() -- Clones the billboard.
local textlabel = PlayerBillboard.TextLabel -- A reference to the new TextLabel parented under PlayerBillboard.
local stage5 = workspace:WaitForChild("Stage5") -- Change "Stage5" to the name of your stage5 part.
local stage11 = workspace:WaitForChild("Stage11") -- Change "Stage11" to the name of your stage11 part.
-----------------------------------------------------------------------------------------------------------------------------
game.Players.PlayerAdded:Connect(function(player) -- Checks if the player has joined the game.
local character = player.Character or player.CharacterAdded:Wait() -- Gets the character of a player
PlayerBillboard.Parent = character:WaitForChild("Head") -- Gives every player that joins the game a nametag
end)
stage5.Touched:Connect(function(hit) -- Checks if stage5 has been touched.
if hit.Parent:FindFirstChild("Humanoid") then -- Checks if what touched the part is player
textlabel.Text = "Pro" -- The text of the nametag becomes 'Pro' when the player reaches stage5
end
end)
stage11.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then -- Checks if what touched the part is player
textlabel.Text = "Legend" -- The text of the nametag becomes 'Legend' when the player reaches stage11
end
end)
Now edit the code in your own way! I don’t know how For example, if you want to make it display the nametag “Expert” when the player reaches stage100, you can edit the code like this
local stage100 = workspace:WaitForChild(--Add quotation marks here, then put the name of your Stage100 part inside the quotation marks.)
stage100.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
textlabel.Text = "Expert"
end
end)
See? It’s easy. Just copy and paste, but edit it in your own way!
Hope it helps!
I know … the comments written in the script are quite overwhelming. I hope you understand how the script works … I’m not the best teacher
That’s very easy. I thought it’s something more complex
Anyway, if you want to make the nametag Noob when the player joins the game, and then change it when the player reaches stage2, just go to the TextLabel and change its Text to “Noob”. That nametag will be obtained once the player joins the game.
If you want to make the player obtain a new nametag when they reach stage2, copy and paste that code.
local stage2 = workspace:WaitForChild(--Add quotation marks here, then put the name of your Stage100 part inside the quotation marks.)
stage100.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
textlabel.Text = --Add quotation marks here, and put the new nametag inside them.
end
end)
Not really, I would like something a little better done, for learning but also for better organization,
in this style:
All the nametags in the replicatestorage > in a server script, detect the leaderstats with the stages and the rest… > and then if the player has less than 2 stages then he gets the nametag noob > if the player is at stage 5 or less, then he gets nametag pro…
to do :
stage 0 = noob
stage 1 = noob
stage 2 = pro
stage 3 = pro
stage 4 = legend
stage 5 = legend…
and without necessarily creating a textlabel for each stage
and I made sure that it was in a different textlabel because I added an animate gradient with the tween service for a specific nametag
did you know how to do it, that would help me understand how to assign a value with a verification of the leaderstats, I know that i need have to use things like that “<= or >=” but I wouldn’t be able to perfectly create code optimized against exploiters.
You’re not making a TextLabel for each stage. You are making one TextLabel, but you are changing the Text property of the TextLabel as the player reach more stages.
You can do this by adding a boolean to check if the player has less than stage2, and adding another boolean to check if the player has less than stage5
Like this
local hasReachedStage2 = false
if hasReachedStage2 == false then
TextLabel.Text = "Noob"
end
stage2.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hasReachedStage2 = true
end
end)
if hasReachedStage2 == true then
TextLabel.Text = "Pro"
end
-- Another example for more understanding
-- Let's say you want to give the player nametag "Legend" if he has more than 10 stages
local hasReachedStage10 = false
if hasReachedStage10 == false then
TextLabel.Text = "Pro"
end
Stage10.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
hasReachedStage10 = true
end
end)
if hasReachedStage10 == true then
TextLabel.Text = "Legend"
end
Well I haven’t learnt UIgradients yet, so I don’t know what they are or how they are used. Sorry!
The script is quite overwhelming … I know. But does it make sense for you?
Hey, for connivence I wouldn’t recommend doing it this way. Repeated code tends to make debugging a big issue.
Instead, here is my solution:
-- Create a table which coordinates the nametags with the minimum stage
local stage_nametags = {
noob = 0,
pro = 2,
legend = 4
}
local function getNametagByStage(stage: number)
local selectedNametag, selectedMinStage = nil, -1 -- -1 is just supposed to be a very low number
-- Essentially the code looks through every value in the table
-- and finds the greatest minimum stage that is less than the given stage.
for nametag, minStage in stage_nametags do
if stage > minStage and minStage > selectedMinStage then
selectedNametag = nametag
selectedMinStage = minStage
end
end
return selectedNameTag
end
Firstly, welcome back to the DevForum, as you haven’t posted since 17 Feb.
Secondly, yea this is a better way, but I don’t use Tables when making games as they complicate things for me actually. I usually tend to stay simple when it comes to ModuleScripts and Tables
i.e I don’t use Tables or ModuleScripts at all.
But again, your solution is much better and organized
There, I updated it and completed it. I accidently posted it without it being complete
Anyways, I highly recommend learning tables because when you limit yourself from tables, your code can get extremely messy. You restrict yourself from using object oriented programming and many other functionality.
Is any reason in particular you don’t use tables/modulescripts and don’t go through the effort of learning how to use them? I know that sounds like a diss but it really isn’t, I’m genuinely curious.
I’m not really sure what your collect system is, sorry. But here’s a quick rundown of my thoughts on ModuleScripts and tables:
First, even though they are fundamentally similar, the uses of ModuleScripts and tables are not the same.
ModuleScripts help split code up while still being accessible by other scripts. This is why functions are most often stored within them. They are the alternative to creating thousand-line scripts that are pains to debug and storing values within the global table.
Tables, on the other hand, are used to not only store similar data, but to also iterate through it. This is essential for automation and removing repeated code. Lets say that you had to kill every player in the server. How would you do that without tables (specifically Lua arrays in this case)?