Nametag script breaking

I have a script in my game that creates custom nametags and should look like this:


This works when I use it in studio or test it in the full Roblox client. however, whenever I joined using my alt to test it in Roblox, the nametag did not show up. I have also tried to see if it was only on the alts side, but when I joined with my main only my main had the nametag and not the alt. One thing to note though is that I joined using the Microsoft version of Roblox for my alt and I don’t know if that could have messed with it, but I will still need it to work anyways if I’m to release it.
Code:

local rep  = game:GetService("ReplicatedStorage")
local nametag = rep:WaitForChild("NameTag")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local head = char:WaitForChild("Head")
		local Hum = char:WaitForChild("Humanoid")
		local text = nametag:Clone()
		local PlayersGUIName = text.GUIName -- There are two parts of the GUI, this one is for the players name
		
		Hum.DisplayDistanceType = "None" -- Turns off the default Roblox nametag
		PlayersGUIName.Text = player.DisplayName
		text.Adornee = head
		text.Parent = head
	end)
end)
3 Likes

Where does this script take place? Like what is it under.

2 Likes

its under Server script service

1 Like

Have you tried putting this into ReplicatedStorage? So when players join it duplicates itself onto the other players.

Ok, I will try that and see if it works.

1 Like

Did this seem to work for you?

No the whole script seemed to break

I can’t tell what exactly is the problem in your script, but I re-created your script in my own way and it works perfectly. (Put the NameTag in the Script)

local players = game:GetService("Players")

local function characterAdded(character)
	repeat wait() until character:FindFirstChild("Humanoid") and character:FindFirstChild("Head")
	character.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	
	local nametag = script.NameTag:Clone()
	nametag.PlayersGUIName.Text = character.Name
	nametag.Parent = character.Head
end

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(characterAdded)
	if player.Character then
		characterAdded(player.Character)
	end
end)

Ok, thanks for your help, it works now