How to script a colour for a rank?

So I was watching a video from a while back, and I noticed how someone had a different coloured rank to everyone else due to their role in the group.

I was wondering how you would script this, here is an example:
image

Any help would be appreciated, thanked!

Do you know how to already insert nametags into a roblox player?

I could probably do this, send me the download file of the overhead.

This actually isn’t to difficult. Check the users rank in the group, and if it matches, set the TextColor3 value of the nametag.

Here is the script, so if anyone could help it would mean loads, thanks!

local groupID = 12012108

game.Players.PlayerAdded:Connect(function(player)
	local groupRank = player:GetRoleInGroup(groupID)
	local clone = script.Rank:Clone()
	clone.Parent = game.Workspace:WaitForChild(player.Name).Head
	clone.Frame.Name1.Text = player.Name
	clone.Frame.Rank.Text = groupRank
	
	player.CharacterAdded:Connect(function()
		local groupRank = player:GetRoleInGroup(groupID)
		local clone = script.Rank:Clone()
		clone.Parent = game.Workspace:WaitForChild(player.Name).Head
		clone.Frame.Name1.Text = player.Name
		clone.Frame.Rank.Text = groupRank
	end)
end)

I don’t see any line of code which assigns a color in this script … ?

For one thing, you’re missing a line of code that will assign a color to a specific role. I don’t really know about the rest of it, though.

That’s the part I need, the line to assign the colour.

local groupID = 12012108

game.Players.PlayerAdded:Connect(function(player)
	local groupRank = player:GetRoleInGroup(groupID)
	local clone = script.Rank:Clone()
	clone.Parent = game.Workspace:WaitForChild(player.Name).Head
	clone.Frame.Name1.Text = player.Name
	clone.Frame.Rank.Text = groupRank
	
	player.CharacterAdded:Connect(function()
		local groupRank = player:GetRoleInGroup(groupID)
		local clone = script.Rank:Clone()
		clone.Parent = game.Workspace:WaitForChild(player.Name).Head
		clone.Frame.Name1.Text = player.Name
		clone.Frame.Rank.Text = groupRank
        if groupRank >= minRank then
            clone.Frame.Rank.TextColor3 = Color3.fromRGB(color3)
	end)
end)

Here, replace color3 with a color3 value and replace minRank with the minimum rank ID.

Thanks so much! I’ll go test it now!

No problem! I hope you enjoy.

LOL I’m stupid I forgot the end. @Deleted_User12

local groupID = 12012108

game.Players.PlayerAdded:Connect(function(player)
	local groupRank = player:GetRoleInGroup(groupID)
	local clone = script.Rank:Clone()
	clone.Parent = game.Workspace:WaitForChild(player.Name).Head
	clone.Frame.Name1.Text = player.Name
	clone.Frame.Rank.Text = groupRank
	
	player.CharacterAdded:Connect(function()
		local groupRank = player:GetRoleInGroup(groupID)
		local clone = script.Rank:Clone()
		clone.Parent = game.Workspace:WaitForChild(player.Name).Head
		clone.Frame.Name1.Text = player.Name
		clone.Frame.Rank.Text = groupRank
        if groupRank >= minRank then
            clone.Frame.Rank.TextColor3 = Color3.fromRGB(color3)
end
	end)
end)
1 Like

image
Nothing showed up in the console-

That’s probably because there is no color after this:

If you wanted red, I believe you would do this:

if groupRank >= minRank then
            clone.Frame.Rank.TextColor3 = Color3.fromRGB(255,0,0)

You can customize the color too, there should be a color wheel that pops up when you select those numbers.

I did that, nothing happended

Check output. Is there anything there?

Nope, nothing was in the output.

Did you update the rankID and groupID?

Yes, here’s the script:

local groupID = 11501504

game.Players.PlayerAdded:Connect(function(player)
	local groupRank = player:GetRoleInGroup(groupID)
	local clone = script.Rank:Clone()
	clone.Parent = game.Workspace:WaitForChild(player.Name).Head
	clone.Frame.Name1.Text = player.Name
	clone.Frame.Rank.Text = groupRank

	player.CharacterAdded:Connect(function()
		local groupRank = player:GetRoleInGroup(groupID)
		local clone = script.Rank:Clone()
		clone.Parent = game.Workspace:WaitForChild(player.Name).Head
		clone.Frame.Name1.Text = player.Name
		clone.Frame.Rank.Text = groupRank
		if groupRank == 255 then
			clone.Frame.Rank.TextColor3 = Color3.fromRGB(85, 170, 255)
		end
	end)
end)


and this is the output

We have some really messy code here.

For example:

This is copy and paste code, we also define groupRank twice.

The issue that is causing the main problem in this code is player:GetRoleInGroup(groupID).

The GetRoleInGroup Player function returns the player’s role in the group as a string, or Guest if the player isn’t part of the group.

In order to get the rank in the group we must use player:GetRankInGroup().

In order to clean up our code, this is what we can do (I tried to explain the code for you in comments):

local groupID = 10392184 --Define Group Id

game.Players.PlayerAdded:Connect(function(player) --When the played joins, define the player.
	player.CharacterAdded:Connect(function(character) --When the players character loads in run the code below.
		local groupRank = player:GetRankInGroup(groupID) --Get the Rank from the player we defined above.
		local clone = script.Rank:Clone() --Clone the Rank.
		clone.Parent = character.Head --Set the clone parent to the character's head.
		clone.Frame.Name1.Text = player.Name -- Set the text of the "Name1" object to the player's name.
		clone.Frame.Rank.Text = player:GetRoleInGroup(groupID) --Set the "Rank" to the role in the group.
 		if groupRank == 255 then --If the groupRank defined above is 255, then. 
			clone.Frame.Rank.TextColor3 = Color3.fromRGB(85, 170, 255) --Set the color of the cloned rank.
		end
	end)
end)



I hope this helps, if you have any questions with the code feel free to ask me, if this fixes your issue be sure to mark this post as solution!