User And Rank Tag Disappearing When Player Dies

Hello,
Last post of the day. Now, I have a script that displays the players name, and rank above their head. The script works perfectly fine, no errors, no issues. But I have discovered that if you reset/die the rank and username disappears. Does anyone know how to make it so that the rank and username stays when the player resets?

Here’s the script

local rep = game:GetService("ReplicatedStorage")
local tag = rep.NameTag

game.Players.PlayerAdded:Connect(function(player)

	local char = player.Character or player.CharacterAdded:Wait()

	local head = char.HumanoidRootPart

	local hum = char.Humanoid
	hum.DisplayDistanceType = "None"

	local newTag = tag:Clone()
	newTag.Enabled = true
	newTag.Name = player.Name.."Tag"
	newTag.Devposition.Text = "Player"
	newTag.Username.Text = player.Name
	newTag.Parent = head
	newTag.Handler.Disabled = false

	if  player.Name == "matermoter28" then
		newTag.Devposition.Text = "Owner"
		newTag.Devposition.TextColor3 = Color3.fromRGB(235, 0, 0)
		newTag.Devposition.Owner.Enabled = true
	elseif player.Name == "szalio" then
		newTag.Devposition.Text = "Builder"
		newTag.Parent = head
		newTag.Devposition.TextColor3 = Color3.fromRGB(0, 235, 0)
		newTag.Devposition.Builder.Enabled = true
	elseif player.Name == "imnotlycky" then
		newTag.Devposition.Text = "Helper"
		newTag.Parent = head
		newTag.Devposition.TextColor3 = Color3.fromRGB(0, 0, 235)
		newTag.Devposition.Builder.Enabled = true
	elseif player.Name == "tkuski08" then
		newTag.Devposition.Text = "Developer"
		newTag.Devposition.TextColor3 = Color3.fromRGB(85, 255, 255)
		newTag.Devposition.Builder.Enabled = true
		else
	end	
end)

game.Players.PlayerAdded:Connect(function(player) < thats your issue. The tag only gets put in when a player joins. You need to add CharacterAdded.

Player.CharacterAdded (roblox.com)

2 Likes

Thank you! I just cant find out how to write it… lol, pretty confusing.

Edit: Found it out!!