Nametags with leaderstats (for obby or other)

Hello, I would like to learn how to make a name tag system that would be functional with the leaderstats, example:

The player is at stage 5 = it displays the “Pro” name tag above him

The player is at stage 11 = it displays the name tag “Legend” above him.

I looked for lots of tutorials or alternative solutions but most of them make nametags for group members or for individual players with their IDs.

Can you help me or send me a link from someone who talks about it. Please ?

and do that with a module, it’s a good idea ?

image

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.

Run a function when the stage changes it checks if the players stage >= 5 and stage < 11
If so update the text on the billboardgui

  • Create a BillboardGui in ServerStorage

  • Create a TextLabel under BillboardGui

  • 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 TextLabel Text 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

:sweat_smile:

1 Like

Thank you very much, I will try to adapt it, and also I will try to add some tweens gradient color, and I will tell you that tomorrow, thank you!!

1 Like

No problem!

Hope it works for you!

ah btw, how do that but without touched ?

I would like the script to check if the player has the required stage and then give him the rank, that would be much better

how it’s possible ?

1 Like

I don’t really get what you mean by that.

But why’d you make it harder for you to read the script?

Touched is the easiest event for such functions, and it does the job perfectly. Why don’t you want Touched in the script?

Most obby games devs use Touched for these functions, and everything is going as intended.

Touched is easier to read and understand.

There is one thing I can’t do, how to do it:

when the player join the game, he directly obtains the nametag “Noob” and then if he hit stage 2 he obtains a new nametag…

1 Like

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)

Does everything make sense?

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

image

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.

1 Like

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
2 Likes

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 :+1:

I don’t even understand how your solution works. :new_moon_with_face:

There, I updated it and completed it. I accidently posted it without it being complete :sweat_smile:

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.

1 Like

I know how to use them, and I’m able to use them, but I don’t use them as I still don’t realize why they are important.

But I’ll try to use them inside my game, which has a collect system.

Are they (ModuleScripts and Tables) needed for such systems?

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)?

1 Like

Thanks for your explanation! I get the difference between them :+1: :slightly_smiling_face:

FireAllClients()

Lets take this to DM, I don’t want to flood this topic anymore :slight_smile:

1 Like

This is what I’m looking for!! This is how I want to proceed in my games, I’m going to try to learn that!

Thank you very much and thank you to DeVague_RBLX who tried to understand me! ty

I will try to create a script module for the table, I would like to see if it works, it will help me later.

1 Like