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:
Can anyone help?
ps: I am trying to do this as a beginner scripter.
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)
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.