Problem with creating a nametag with developer only text

Hello, I am making a nametag but I am struggling with the scripting part.

What am I trying to achieve?
I am trying to make a nametag that shows above the players head, if the player is a developer, in which is me, there will be another TextLabel above the name text, which will say “Developer”.

What is my issue?
I have written a script from a tutorial, and have added my own part at the bottom, but the nametag doesnt show in game, and I don’t know if the developer only bit will work.

What have I tried?
I haven’t really tried much, since I didn’t think people would have the same issue.

Script:

local nametag = game:GetService("ReplicatedStorage"):WaitForChild("Nametag")

game.Players.PlayerAdded:Connect(function(player)
	game.Players.CharacterAdded:Connect(function(char)
		
		local uiclone = nametag:Clone()
		uiclone.Name.Text = player.Name
		uiclone.Rank.Text = "Newbie"
		uiclone.DeveloperOnly.Text.Visible = false
		uiclone.Parent = char.Head
	end)
	
	if player.Name == "YTFUZE123" then
		uiclone.DeveloperOnly.Text.Visible = true
	end
end)

The billboardgui:
Capture

Can anyone help?

ps: I am trying to do this as a beginner scripter.

1 Like

First off;

I suggest changing this to player.UserId, only if you would want to change your name;
And then, set the uiclone Adornee?

4 Likes

Mmm… AFAIK that doesn’t affect anything…

1 Like

Shoot, just realized that it doesn’t effect it, sorry!

2 Likes

I have tried this, although I don’t know if I used the Adornee correctly.

game.Players.CharacterAdded:Connect(function(char)

	local uiclone = nametag:Clone()
	uiclone.Name.Text = player.Name
	uiclone.Rank.Text = "Newbie"
	uiclone.DeveloperOnly.Text.Visible = false
	uiclone.Adornee = char.Head

	if player.Name == "YTFUZE123" then
		uiclone.DeveloperOnly.Text.Visible = true
	end
end)
1 Like

I see a small problem on the CharacterAdded event, use the player from the PlayerAdded parameter.
So, do this:

local nametag = game:GetService("ReplicatedStorage"):WaitForChild("Nametag")

    game.Players.PlayerAdded:Connect(function(player)
    	player.CharacterAdded:Connect(function(char)
    		
    		local uiclone = nametag:Clone()
    		uiclone.Name.Text = player.Name
    		uiclone.Rank.Text = "Newbie"
    		uiclone.DeveloperOnly.Text.Visible = false
    		uiclone.Parent = char.Head
    	end)
    	
    	if player.Name == "YTFUZE123" then
    		uiclone.DeveloperOnly.Text.Visible = true
    	end
    end)

Let me know if this works!

2 Likes

Here’s some better code if you want the GUI to be above the player’s head even after the player’s death:

local nametag = game:GetService("ReplicatedStorage"):WaitForChild("Nametag")

local function CharacterAdded(Character)
	local Player = game.Players:GetPlayerFromCharacter(Character)
	local uiclone = nametag:Clone()
	uiclone.Name.Text = Player.Name
	uiclone.Rank.Text = "Newbie"
	uiclone.DeveloperOnly.Text.Visible = false
	uiclone.Parent = Character.Head
	if Player.Name ~= "YTFUZE123" then
		return
	elseif Player.Name == "YTFUZE123" then
		uiclone.DeveloperOnly.Text.Visible = true
	end
end

game.Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(CharacterAdded)
end)
2 Likes

Doesn’t seem to be working. got to write 30

1 Like

Can you tell me the error in the output?

2 Likes

not sure if this would change anything but after the

game.Players.PlayerAdded:Connect(function(player)
	game.Players.CharacterAdded:Connect(function(char)
		
		local uiclone = nametag:Clone()
		uiclone.Name.Text = player.Name
		uiclone.Rank.Text = "Newbie"
		uiclone.DeveloperOnly.Text.Visible = false
		uiclone.Parent = char.Head
	end)

you see the end)?
try moving that all the way to the bottom with the rest of them and lmk if it helps

1 Like

ServerScriptService.Nametag:6: attempt to index string with ‘Text’

1 Like

Change the code that you have to that code.

1 Like

oh I get it ok so basically make it this

local nametag = game:GetService("ReplicatedStorage"):WaitForChild("Nametag")

game.Players.PlayerAdded:Connect(function(player)
	game.Players.CharacterAdded:Connect(function(char)
		
		local uiclone = nametag:Clone()
		uiclone.Name.Text = player.Name
		uiclone.Rank.Text = "Newbie"
		uiclone.DeveloperOnly.Visible = false
		uiclone.Parent = char.Head
	end)
	
	if player.Name == "YTFUZE123" then
		uiclone.DeveloperOnly.Visible = true
	end
end)
1 Like

To fix your error make this your script

local nametag = game:GetService("ReplicatedStorage"):WaitForChild("Nametag")

game.Players.PlayerAdded:Connect(function(player)
	game.Players.CharacterAdded:Connect(function(char)
		
		local uiclone = nametag:Clone()
		uiclone.Name.Text = player.Name
		uiclone.Rank.Text = "Newbie"
		uiclone.DeveloperOnly.Visible = false
		uiclone.Parent = char.Head
	end)
	
	if player.Name == "YTFUZE123" then
		uiclone.DeveloperOnly.Visible = true
	end
end)
1 Like

This won’t work after they respawn.

1 Like

well yea but its gonna fix this

1 Like

My script works after they respawn.

1 Like

Read it again, I edited the script.

2 Likes

Try this:

local nametag = game:GetService("ReplicatedStorage"):WaitForChild("Nametag")

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local clone = nametag:Clone()
clone.TextLabel.Text = player.Name
clone.Parent = char.Head
if player.Name == "YTFUZE123" then
clone.TextLabel.Text = "whatever text"
end
end)
end)

Hello there. I believe I might have a solution for you.

People often use something like this to clone:

local Original = game.ServerStorage:WaitForChild("Object")
local Clone = Original:Clone()

Clone.Parent = workspace

However in some cases this can cause a nil property locked error that will prevent the script from ever running again (depends on what type of function is used) and it’s not very clean. For a nametag however, using this:

local Original = game.ServerStorage:WaitForChild("Object")

Original:Clone().Parent = workspace

is much better as it won’t clone something to a variable, and keep using that variable. It will use another variables original path, and immediately set it without any use of a variable holding our clone. I believe that could be an issue of some things, but there was other errors that I noticed in your code that I knew wouldn’t work.

Try this code! Make sure you move the script to ServerScriptService, and your Nametag to ServerStorage. Also make sure the “DeveloperOnly” text object has the Visible property disabled in the properties window.

-- Put your NameTag within ServerStorage instead since this is a ServerScript. No real difference, but can be more secure. --
local NameTag = game:GetService("ServerStorage"):WaitForChild("Nametag")

-- Make sure this script is inside ServerScriptService! --
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		
		-- Instead of making a clone and setting it to a variable, we simply clone it to the character than define to prevent
		-- Property Locked nil errors (and other stuff)
		NameTag:Clone().Parent = char.Head
		
		-- Define the newly cloned NameTag so we can edit it later --
		local NewNameTag = char.Head:WaitForChild("Nametag")
		
		-- Set the "Name" text to the Players Name, and set the default rank to "Newbie" --
		NewNameTag:FindFirstChild("Name").Text = player.Name
		NewNameTag:FindFirstChild("Rank").Text = "Newbie"
		
		-- Use UserId to always work with a specific user only. --
		if player.UserId == 1909291761 then
			-- Make the DeveloperOnly text visible and set it to a custom text --
			NewNameTag.DeveloperOnly.Visible = true
			NewNameTag.DeveloperOnly.Text = "InsertCoolDevTagHere"
		end
		
	end)
end)

Let me know if this works. I’ll be happy to assist further.

2 Likes