Looking at your code, I can see the issue. The player name isn't being set because you're creating the nametag but never actually setting the initial text for the "Player name" TextLabel.
Here's the fixed code with the necessary additions:
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)
-- 🔹 SET THE PLAYER NAME
local nameLabel = clone:FindFirstChild("Player name")
if nameLabel and nameLabel:IsA("TextLabel") then
nameLabel.Text = plr.Name
print("[Nametag] Set name to", plr.Name)
else
warn("[Nametag] Couldn't find 'Player name' TextLabel")
end
-- 🔹 SET THE PLAYER RANK
local rankLabel = clone:FindFirstChild("Player Rank")
if rankLabel and rankLabel:IsA("TextLabel") then
local groupId = 36034298
local rank = "Guest"
if plr:IsInGroup(groupId) then
rank = plr:GetRoleInGroup(groupId)
end
rankLabel.Text = rank
plr:SetAttribute("GroupRank", rank)
print("[Nametag] Set rank to", rank)
else
warn("[Nametag] Couldn't find 'Player Rank' TextLabel")
end
-- Team assignment
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
end)
end)
-- Rest of your code remains the same...
The key changes are:
- After cloning the nametag, I added code to find the "Player name" TextLabel and set its text to
plr.Name
- I also moved the rank setting logic into the character spawn event so it happens automatically when the player spawns
- Added debug prints to help track what's happening
This ensures that both the player name and rank are set immediately when the nametag is created, rather than waiting for a RemoteEvent to fire.