Name tag script not showing when reset

I have a nametag script that I want a user to be above the player’s head.

The nametag stays above the user’s head until they reset. I would like it to stay above the users head even after they reset.

SCRIPT 1 IN SCRIPTPLAYERSCRIPTS

        while true do
    wait()
    game:GetService('Players').PlayerAdded:Connect(function(player)
    	player.CharacterAdded:Connect(function(character)
    		character:WaitForChild("Humanoid").Died:Connect(function()
    			local rs = game:GetService("ReplicatedStorage")
    local remotefolder = rs:WaitForChild("RankFolder")
    local remote = remotefolder:WaitForChild("RankPlayerOnRespawn")

    remote:FireServer()
    		end)
    	end)
    end)

    for i = 0,1,0.03 do
        wait()
    end

SCRIPT 2 IN SCRIPTPLAYERSCRIPTS:

while true do
wait()
game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			
local isAdmin = {["MysteriouslyMythical"] = true, ["DEATHRON6"] = true} 

game.Players.PlayerAdded:connect(function(player)
	if isAdmin[player.Name] then
  wait(2)  
 while wait() do		
		local rc = math.random(0,255)
local gc = math.random(0,255)
local bc = math.random(0,255)
local r = rc / 255
local g = gc / 255
local b = bc / 255
local c = Color3.new(r, g, b)
for i = 0,1,0.03 do
    wait()
    player.Character.Rank.Frame.Name1.TextColor3 = player.Character.Rank.Frame.Name1.TextColor3:lerp(c,i)
    player.Character.Rank.Frame.TextLabel.TextColor3 = player.Character.Rank.Frame.Name1.TextColor3:lerp(c,i)
end
end
end
end)
end

**SCRIPT 3 IN SERVERSCRIPTSERVICE: **

for i = 0,1,0.03 do
wait()
while true do
	wait()
--//\\ Config //\\
local Admins = {
    "DEATHRON6"; -- Username example
    165035060; -- User ID example
    
}

local GroupId = 5992132 -- Your group ID
local DefaultRank = "Guest" -- Change what you want instead of Guest 
local Speed = 0.1 -- How fast you want it to change color. Default is 0.1-0.3



--//\\ Stuff below do not touch --//\\
function IsWhitelisted(Player)
    for _,Whitelisted in pairs (Admins) do
        if type(Whitelisted) == "string" and string.lower(Whitelisted) == string.lower(Player.Name) then
            return true
        elseif type(Whitelisted) == "number" and Whitelisted == Player.UserId then
            return true
        end
    end
    return false
end



local rs = game:GetService("ReplicatedStorage")
local remotefolder = rs:WaitForChild("RankFolder")
local remote = remotefolder:WaitForChild("RankPlayerOnRespawn")

remote.OnServerEvent:connect(function(Player)
	if not Player then
		print("ERROR Can't fetch the player")
	end
	local pRank = Player:GetRoleInGroup(GroupId)
	wait(1)
	local ui = script.Rank:Clone()
	ui.Parent = Player.Character
	ui.Adornee = Player.Character.Head
	
	while not Player.Character.Humanoid do wait() end
	Player.Character.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	local frame = ui.Frame
	local name = frame.Name1
	local role = frame.TextLabel
	
	name.Text = Player.Name
	if Player:IsInGroup(GroupId) then
	role.Text = pRank
	else
    role.Text = DefaultRank
    end	
    
	
	-- //\\ Custom Name //\\
	-- You don't need to use Brick.Red() for colors. It is all RGB based coloring system
	if name.Text == "ROBLOX" then -- Example
		name.TextStrokeTransparency = 0
		name.TextColor3 = Color3.new(0, 0, 0) -- Text Color for username
		role.TextStrokeTransparency = 0
		role.TextColor3 = Color3.new(0, 0, 0) -- Text Color for rank
		role.Text = "ROBLOX | Admin" -- Example of what the text should be
	elseif name.Text == "greatgamer59" then
			name.TextStrokeTransparency = 0
		name.TextColor3 = Color3.new(0, 255, 0) -- Text Color for username
		role.TextStrokeTransparency = 0
		role.TextColor3 = Color3.new(0, 255, 0) -- Text Color for rank
		role.Text = "Epic owner :D" -- Example of what the text should be
	end

	

	if IsWhitelisted(Player) or game.MarketplaceService:UserOwnsGamePassAsync(Player.UserId) then -- If you don't want VIPs getting rainbow just remove everything after or but keep then
      
wait(2)  
 while wait() do		
		local rc = math.random(0,255)
local gc = math.random(0,255)
local bc = math.random(0,255)
local r = rc / 255
local g = gc / 255
local b = bc / 255
local c = Color3.new(r, g, b)
for i = 0,1,0.03 do
	wait()
    wait(Speed)
    Player.Character.Rank.Frame.Name1.TextColor3 = Player.Character.Rank.Frame.Name1.TextColor3:lerp(c,i)
    Player.Character.Rank.Frame.TextLabel.TextColor3 = Player.Character.Rank.Frame.Name1.TextColor3:lerp(c,i)
end
end
end
end)
end
end

Thanks, in advanced

It’s incredibly hard to understand how this system is supposed to work, it’s very inefficient and unorganized. It looks like there are 2 local scripts and 1 server script. You’re using Players.PlayerAdded locally which is super unnecessary, and you’re using it in two local scripts instead of just combining that 1 function into 1 script. All you need to do to make this work is 1 server script which contains code that does the following:

  • Captures the event every time a player’s character is added
  • Creates a function attached to said event which clones a BillboardGUI nametag (I assume it’s a billboardGUI you’re using) into the player’s head or humanoid root part.
  • Since you seem to have some sort of admin system, you could still keep the Admin table in the server script and make it so the script will act one way if the player whose character was added is an admin, and have it act another way if that is not the case.
  • If you’re planning to have your script have these color changing effects that I seem to see in your server script, just move that into a local script inside the name tag itself. It doesn’t need to be attached to this function.

This will be much easier to do it this way than the methods you posted above, no remote events needed or anything.

SIDE NOTE: these days you should use :Connect instead of :connect

2 Likes

Sorry about that. I was on a project and this is the script which I had to edit. (I recoded everything but could not figure this out). I have fixed the script, and done what you have adressed. Thanks.

1 Like