Problem with Nametag script

Hey! I’ve been doing a nametag script but when testing there was like a tiny problem. Eveytime someone dies or joins (CharacterAdded), the badge for the gamepass owners will get always more. Example: You own VIP and you join. You will get a PC badge when you are playing on PC for example and then you will also get a small crown as badge. Problem is now: When someone gets a new char, you get like then a second crown and this just always and always. Here’s my code on the server side:

local gamepasses = {
	["VIP"] = {
		["Id"] = 7375868;
		["Emojie"] = "👑";
	};
	["FreeWorld"] = {
		["Id"] = 46868967;
		["Emojie"] = "🌍";
	};
	["Investidor"] = {
		["Id"] = 15407453;
		["Emojie"] = "🌟"
	}
}

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local newNametag = script.BillboardGui:Clone()
		newNametag.Frame.Username.Text = player.Name
		newNametag.Frame.Rank.Text = player:GetRoleInGroup(5126518)
		char.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
		game.ReplicatedStorage.CheckPlayerDevice:FireClient(player)
		game.ReplicatedStorage.CheckPlayerDevice.OnServerEvent:Connect(function(playerName,realName,device)
			if player.Name == realName.Name then
				print("changing")
				if device == "PC" then
					print("pc, yes")
					newNametag.Frame.Badges.Text = "🖥️"
				else
					if device == "MOBILE" then
						newNametag.Frame.Badges.Text = "📱"
					end
				end
			end
			for i,v in pairs(gamepasses) do
				if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,v.Id) == true then
					newNametag.Frame.Badges.Text = newNametag.Frame.Badges.Text.."/"..v.Emojie
				end
			end
			if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, gamepasses.VIP.Id) == true then
				newNametag.Frame.Username.Script.Disabled = false
			else
				newNametag.Frame.Username.UIGradient:Destroy()
			end
			repeat
				wait()
			until player.Team ~= nil
			for i,v in pairs(newNametag.Frame:GetChildren()) do
				if v:IsA("TextLabel") then
					v.TextColor = player.TeamColor
				end
			end
			newNametag.Parent = char.HumanoidRootPart
		end)
	end)
end)

And that’s on client side:

game.ReplicatedStorage.CheckPlayerDevice.OnClientEvent:Connect(function()
	if game:GetService("UserInputService").KeyboardEnabled then
		print("PC")
		game.ReplicatedStorage.CheckPlayerDevice:FireServer(game.Players.LocalPlayer,"PC")
	else
		print("MOBILE")
		game.ReplicatedStorage.CheckPlayerDevice:FireServer(game.Players.LocalPlayer,"MOBILE")
	end
end)

Anyone have any idea how to fix this?

1 Like

I’m not entirely sure what the issue is… but in the line where you add a crown or emoji, you can add a if to check if the person already has a crown in the name tag.

Yea ig this could work but like. Why is it reapeating for EVERYONE? xd

I think this could be why, there is a onserverevent inside of the function. You may want to try doing it separately instead.

1 Like

Oh alright! Thank you! I’mma have a look into it! :slight_smile: