I'll help you troubleshoot the issue with the player name not being set. Let's review the code and suggest some modifications:
local NameTag = game.ReplicatedStorage.Nametag
local Players = game:GetService('Players')
local NameSetter = game.ReplicatedStorage.NameSetter
local RankSetter = game.ReplicatedStorage.RankSetter
local Teams = game:GetService('Teams')
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
print('[Nametag] Character spawned for', plr.Name)
local head = char:WaitForChild("Head", 5)
if not head then
warn("[Nametag] Couldn't find Head for", plr.Name)
return
end
local clone = NameTag:Clone()
if not clone:IsA("BillboardGui") then
warn("[Nametag] Clone is not a BillboardGui!")
return
end
clone.Name = "Nametag"
clone.Adornee = head
clone.Parent = head
print("[Nametag] Cloned and parented for", plr.Name)
-- 🔹 Explicitly set the player name
local nameLabel = clone:FindFirstChild("Player name")
if nameLabel and nameLabel:IsA("TextLabel") then
nameLabel.Text = plr.Name
end
local teamName = plr:GetAttribute('GroupRank')
local teamToAssign = Teams:FindFirstChild(teamName)
if teamToAssign then
plr.Team = teamToAssign
print("[TeamAssign] Assigned", plr.Name, "to", teamName)
else
warn("[TeamAssign] Team", teamName, "not found!")
end
-- 🔹 Trigger RankSetter for initial rank
RankSetter:FireServer()
end)
end)
-- 🔹 Updated: accepts a name string from the client
NameSetter.OnServerEvent:Connect(function(player, customName)
local char = player.Character
if not char then return end
local head = char:FindFirstChild("Head")
if not head then return end
local nameTag = head:FindFirstChild("Nametag")
if not nameTag then return end
local label = nameTag:FindFirstChild("Player name")
if label and label:IsA("TextLabel") then
local current = label.Text
-- 🔸 Only update if different
if customName and customName ~= "" and customName ~= current then
label.Text = customName
end
end
end)
RankSetter.OnServerEvent:Connect(function(player)
local char = player.Character
if not char then return end
local head = char:FindFirstChild("Head")
if not head then return end
local nameTag = head:FindFirstChild("Nametag")
if not nameTag then return end
local label = nameTag:FindFirstChild("Player Rank")
if label and label:IsA("TextLabel") then
local groupId = 36034298
local rank = "Guest"
if player:IsInGroup(groupId) then
rank = player:GetRoleInGroup(groupId)
end
player:SetAttribute("GroupRank", rank)
label.Text = rank
end
end)
Key changes and suggestions:
-
Added explicit name setting when the character spawns:
- After cloning the nametag, I added code to find the "Player name" TextLabel and set its text to
plr.Name
-
Added a call to RankSetter:FireServer() when the character spawns to ensure rank is set initially