Changing name tag

Hey Developers,

I’m trying to make a system where if your a certain rank in the group above your head on a text label it displays a piece of text e.g if your a High Rank then it says “High Rank” but I also want to script it so if the player has the premium gamepass it fades out and fades in with a new text that says “Premium”. I understand that I need to just change the transparency of the text label but does anybody know how I could manage it? Like how to check what there rank is and if they own the gamepass, and then if they do then how to make it change.

Any help would be appreciated. :heart:

1 Like

You’ll have to prioritize game-passes over specific roles, this can be done in block statements such as:

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local GroupId = 0

Players.PlayerAdded:Connect(function(Player: Player)
	local Rank = Player:GetRankInGroup(GroupId)
	local Role = "No Role"
	if Rank <= 50 then -- prioritize ranks below 50 to roles regarding gamepasses
		if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, 0) then
			Role = "Gamepass Role"
		end
	else -- prioritize ranks above 50 to roles regarding the ranks
		Role = Player:GetRoleInGroup(GroupId)
	end
end)

I’m not trying to make a system that priorities certain things I’m trying to make something that can identify what the players rank is in the group and if they have the game pass, if they then have the gamepass as well as being a high rank then making the textlabel change from saying “premium” to “highrank” every 5 seconds.

You can do this using BillboardGUI’s; here is an example:

I did not fully create the Billboard for you, but you can create one and test around and then export it using the properties.

local HighRanks = { 
    1, 2, 3, 4
} -- Add any high ranks here

local Ranks = {
    "High Rank" == {
        displayAs = "High Rank",
        checkRank = function(player)
           if table.find(HighRanks, player.UserId) then
               return true
           end

           return false
        end
    },
    "Premium" == {
        displayAs = "Premium",
        checkRank = function(player)
            return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 0)
        end
    }
}

local getRank = function(player)
    for i,v in pairs(Ranks) do
       if v.checkRank(player) == true then
          return tostring(i)
       end
    end
    return "None"
end

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAppearanceLoaded:Connect(function(character)
        if getRank(player) ~= "None" then
            local BillboardGui = Instance.new("BillboardGui", character.Head)
            local TextLabel = Instance.new("TextLabel", BillboardGui)
            
            TextLabel.Text = Ranks[getRank(player)]['displayAs']
        end
    end)
end)

If you have any issues, let me know; this is a pretty advanced script I have created and you can add your own conditions and ranks by adding a table, and creating a function with checkRank alongside displayAs for the Display.

You could also move the table for ranks into a module script, and call upon the module script for even cleaner code.

I understand, but you’re asking someone to write the entire script for you. That’s ridiculous, nobody should have to take the time out of their day to write a script for you but kudos to whoever does for their generosity. It’s better you learn something than to have someone do it for you.

Do make sure you make your own billboard GUI, adjust the paths.
Do tell me if this works, I haven’t tested it.

--// Place in Server Script Service
local PlayersService = game:GetService("Players")
local marketplaceService = game:GetService("MarketplaceService")

local function create(Player, GroupID)
    local OverheadGuiObject = game.ReplicatedStorage:FindFirstChild("BillboardGui") -- Whatever your billboardGui is called
    local guiClone = OverheadGuiObject:Clone()
    local character = Player.Character or Player.CharacterAdded:Wait()
    guiClone:FindFirstChild("Name").Text = Player.Name --// nameTextLabel
    guiClone.Rank.Text = Player:GetRoleInGroup(GroupID) --// Rank Text Label
    guiClone.Parent = character.Head
    local premiumGamepass = "ID" --// Change to your gamepass's ID without the ""
    if marketplaceService:UserOwnsGamePassAsync(Player.UserId, premiumGamepass) then
        guiClone.PremiumTextLabel.Visible = true --// Change to premiumtext path
        while wait() do
            for i = 0, 100 do
                local transVal = i/100
                guiClone.PremiumTextLabel.Transparency = transVal -// Change to premiumtext path
            end
        end
    end
    character.Humanoid.NameDisplayDistance = 0
    --// Next Part to Hide the player from seeing their own nametag
    guiClone.PlayerToHideFrom = Player
end


PlayersService.PlayerAdded:Connect(function(Player) -- Fires when the player joins the game
    Player.CharacterAdded:Connect(function(Character) -- Fires each time the players character is added
        local GroupID = "ID" --// Change to your groups ID without the ""
        create(Player, GroupID) -- Player, GroupId
    end)
end)

use this and add onto the rest