I have a custom overhead nametag for players in my game, and it works just fine including when resetting happens. It’s able to remake the nametag as if the user is just newly joining the game.
However, what I now want it to do is take the old nametag the user had before, including any scripts, TextLabels, etc that may have been added or removed after the player joined, and I want to have all that come back after they respawn exactly how it was before — whether the changes align with the original nametag when they first joined or not. This probably has an extremely simple solution I overlooked, but I’m stumped. Any help would be appreciated!
So essentially, you want a player to retain the exact same nametag they had upon respawning as what they had right before they respawned?
If so, a solution to that could be to store a copy of the nametag right before they respawn, then give it back to them upon respawning:
Example
local Players = game:GetService("Players")
local function createDefaultNametag(player, Head)
local groupRank = player:GetRoleInGroup(123456789)
local otg = script.Rank:Clone()
local Frame = otg.Frame
local Name1 = Frame.Name1
local Rank = Frame.Rank
Name1.Text = player.Name
Rank.Text = groupRank
Rank.TextColor = player.TeamColor
otg.Parent = Head
end
local function onPlayerJoin(player)
local updatedNametag
local firstTimeSpawning = true
player.CharacterAdded:Connect(function(Character)
local Head = Character:WaitForChild("Head")
if firstTimeSpawning == true then -- If it's the player's first time spawning into the server...
firstTimeSpawning = false
createDefaultNametag(player, Head) -- Create the default nametag for the player
else
if updatedNametag == nil then
createDefaultNametag(player, Head)
else
updatedNametag.Parent = Head
end
end
end)
player.CharacterRemoving:Connect(function(oldCharacter)
local Head = oldCharacter:WaitForChild("Head")
local existingNametag = Head:WaitForChild("Rank")
if existingNametag then
updatedNametag = existingNametag:Clone()
end
end)
end
Players.PlayerAdded:Connect(onPlayerJoin)
for _, player in Players:GetPlayers() do
task.spawn(onPlayerJoin, player)
end
I’m pretty sure it’ll work, but if it doesn’t, let me know and I’ll see if I can fix it. And if you’d like me to clarify how any of the code works, feel free to ask!
Thanks for the help, this works as expected! I do have a question though about something I think occurred due to this new script, here’s a picture of the output: