Help with replicating a model onto a player

Hi,

I am trying to make a script that replicates a model (in this case a nametag badge) onto every players body, with the surfacegui on the badge displaying their name.

It works perfectly in play test with 2 clients, but in a live game it only replicates it onto the first player that joins, but does not exist on the second player.

Here is my script from ServerScriptService:

print("Nametag server script started")

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local function setupNametag(player, char)
	print("[Nametag] Character loaded:", char.Name)

	local torso = char:FindFirstChild("UpperTorso") or char:FindFirstChild("Torso")
	if not torso then
		warn("[Nametag] Could not find Torso or UpperTorso")
		return
	end
	print("[Nametag] Found torso:", torso.Name)

	local template = ReplicatedStorage:FindFirstChild("Nametag")
	if not template then
		warn("[Nametag] Nametag model not found in ReplicatedStorage")
		return
	end

	local clone = template:Clone()
	clone.Name = "Nametag"

	for _, part in ipairs(clone:GetDescendants()) do
		if part:IsA("BasePart") then
			part.Anchored = false
			part.Massless = true
			part.CanCollide = false
		end
	end

	local nameplate = clone:FindFirstChild("Nameplate")
	if not nameplate then
		warn("[Nametag] Missing Nameplate part in clone")
		return
	end

	nameplate.CFrame = torso.CFrame * CFrame.new(-0.6, 0.5, -0.501)
	local weld = Instance.new("WeldConstraint")
	weld.Part0 = torso
	weld.Part1 = nameplate
	weld.Parent = nameplate
	print("[Nametag] Welded nametag to torso")

	local outline = clone:FindFirstChild("Outline")
	if outline then
		outline.CFrame = torso.CFrame * CFrame.new(-0.6, 0.5, -0.5)
		local weldOutline = Instance.new("WeldConstraint")
		weldOutline.Part0 = torso
		weldOutline.Part1 = outline
		weldOutline.Parent = outline
		print("[Nametag] Welded outline to torso")
	else
		warn("[Nametag] Outline part not found in Nametag clone")
	end

	repeat task.wait() until char:IsDescendantOf(workspace)

	clone.Parent = char

	print("[Nametag] Cloned and parented nametag to character")

	-- Set GUI text
	local gui = nameplate:FindFirstChild("NameGui")
	if gui and gui:FindFirstChild("Username") then
		gui.Username.Text = player.Name
		gui.Enabled = true
		gui:SetAttribute("RobloxGuiVisibilityReplicationHack", true)
		print("[Nametag] Username text set to", player.Name)
	else
		warn("[Nametag] Could not find Username text label")
	end

	print("[Nametag] Setup complete for", player.Name)

	for _, otherPlayer in ipairs(Players:GetPlayers()) do
		if otherPlayer ~= player then
			task.delay(2, function()
				local char = otherPlayer.Character
				if char then
					local seen = char:FindFirstChild("Nametag")
					print("[Debug] Player", player.Name, "checking", otherPlayer.Name, "→ Nametag seen:", seen and true or false)
				end
			end)
		end
	end
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(function(char)
		setupNametag(player, char)
	end)

	if player.Character then
		setupNametag(player, player.Character)
	end
end

for _, player in ipairs(Players:GetPlayers()) do
	onPlayerAdded(player)
end

Players.PlayerAdded:Connect(onPlayerAdded)

And here is a screenshot from the console confirming that it only replicates into one player.

Thank you!

ipairs and pairs are no longer relevant in luau!!! rahhh!!!

1 Like

Hey there, I would recommend confirming this line with the CharacterAdded event as a model can only be applied to a character model, not player instance