Hi! So I have a nametag that I want cloned on the script. For some reason, this function does not work at all:
local bill = game.ReplicatedStorage:WaitForChild("NameTag")
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
if player.Character.Head:FindFirstChild("NameTag") == nil then
local clone = bill:Clone()
clone.Enabled = true
clone.Parent = player.Head
clone.PlayerName.Text = player.Name
clone.Title.Text = "Guest"
end
end)
end)
This function just doesn’t work for some reason and there are no errors in the output. To work around this, I added a wait function and did the same thing:
wait(3)
if plr.Character.Head:FindFirstChild("NameTag") == nil then
print("why")
local new = nametag:Clone()
new.Parent = plr.Character.Head
new.Adornee = plr.Character.Head
local humanoid = plr.Character:FindFirstChildOfClass('Humanoid')
humanoid.DisplayDistanceType = "None"
local uppertext = new.PlayerName
local lowertext = new.Title
uppertext.Text = plr.DisplayName
lowertext.Text = "Guest"
end
But now I’ve run into in issue where I need the characteradded function to work because if the player resets, the nametag won’t be there. How can I get the characteradded function to work or make it so when the player resets or dies, the nametag is cloned again (another workaround)?
To try and debug it, i got rid of the if statement and added a print() with this code:
plr.CharacterAdded:Connect(function(char)
print("starteddddddddd")
--Varibles
local head = char.Head
local newtext = nametag:Clone() --Cloning the text.
local uppertext = newtext.PlayerName
local lowertext = newtext.Title
local humanoid = char.Humanoid
humanoid.DisplayDistanceType = "None"
--Main Text
newtext.Parent = head
newtext.Adornee = head
uppertext.Text = plr.DisplayName --Changes the text to the player's name.
--"If" Statements
--You can add as many of these as you wish, just change it to the player's name.
end)
The print statement triggers when I join and reset, but nothing happens to the nametag. I don’t know how to fix it.
I have had this issue for the past week and you fixed it! Thank you so much! I didn’t know something as simple as a wait statement was all I needed. Thanks again!
They are correct, the ‘CharacterAdded’ event/signal fires whenever the character model is added, not when it has loaded, to correctly wait for a character’s appearance to load listen for the ‘CharacterAppearanceLoaded’ event/signal to fire.
local Game = game
local Players = Game:GetService("Players")
local function OnPlayerAdded(Player)
local function OnCharacterAdded(Character)
if not Player:HasAppearanceLoaded() then Player.CharacterAppearanceLoaded:Wait() end
local Head = Character:FindFirstChild("Head") or Character:WaitForChild("Head")
local BillboardGui = Instance.new("BillboardGui")
BillboardGui.Adornee = Head
BillboardGui.Parent = Head
end
Player.CharacterAdded:Connect(OnCharacterAdded)
end
Players.PlayerAdded:Connect(OnPlayerAdded)