So I have a script that replaces Robloxs Nametag and adds a custom nametag with the player’s name and their team role. It also displays if they are premium and if they have the VIP game pass. But I’m having an issue in which when I join the game it updates and applies the nametag but when I join on an alt it doesn’t appear.
Code
local MarketplaceService = game:GetService("MarketplaceService")
local Chat = game:GetService("Chat")
function NameColor(Player, PlayerName)
PlayerName.TextColor3 = Player.TeamColor.Color
end
function TeamName(Player,GroupRank)
GroupRank.Text = Player.Team.Name
end
_G.NameTagSettings = {}
function SetName(Player, NameTag)
if _G.NameTagSettings[Player.UserId] == Player.Name or not _G.NameTagSettings[Player.UserId] then
NameTag.Text = Player.Name
else
NameTag.Text = _G.NameTagSettings[Player.UserId] .. " ("..Player.Name..")"
end
end
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Head = Character.Head
local Humanoid = Character.Humanoid
Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
local RankGui = script.RankGui:Clone()
local Frame = RankGui.Frame
local PlayerName = Frame.PlayerName
local GroupRank = Frame.GroupRank
local VIP = Frame.Frame.Crown
local premium = Frame.Frame.Premium
NameColor(Player, PlayerName)
Player:GetPropertyChangedSignal("TeamColor"):Connect(function()
NameColor(Player, PlayerName)
end)
SetName(Player, PlayerName)
GroupRank.Text = Player.Team.Name
TeamName(Player, GroupRank)
Player:GetPropertyChangedSignal("Team"):Connect(function()
TeamName(Player, GroupRank)
end)
-- checks if player owns vip
local success, hasPass = pcall(function()
return MarketplaceService:UserOwnsGamePassAsync(Player.UserId, 13428122)
end)
-- gives if they own it
if success and hasPass then
VIP.Visible = true
end
-- checks premium and enables it
if Player.MembershipType == Enum.MembershipType.Premium then
premium.Visible = true
end
RankGui.Parent = Head
end)
end)
function UpdateName(Player)
local Character = Player.Character
if Character then
local Head = Character:FindFirstChild("Head")
if Head then
local RankGui = Head:FindFirstChild("RankGui")
if RankGui then
SetName(Player, RankGui.Frame.PlayerName)
end
end
end
end
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local NameEvents = ReplicatedStorage:FindFirstChild("NameEvents")
local NameTagFunction = Instance.new("RemoteFunction")
NameTagFunction.Name = "NameTag"
NameTagFunction.OnServerInvoke = function(Player, RPName)
if not RPName then
return _G.NameTagSettings[Player.UserId]
end
RPName = Chat:FilterStringForBroadcast(RPName, Player) or Player.Name
if not RPName:find('#') then
if RPName == Player.Name then
_G.NameTagSettings[Player.UserId] = nil
else
_G.NameTagSettings[Player.UserId] = RPName
end
UpdateName(Player)
end
return RPName
end
NameTagFunction.Parent = NameEvents
My account joining the game
Alt account joining the game
Any fixes?