Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do i add colors to certain ranks?

Asked by 9 years ago

I'm not really good with lua so i'm not sure how to do it but i want to know how i can make certain ranks in my group have color. This is a free script that i took.

-- Put this script in the StarterGui.
-- Then change the GroupId to your Group's Id.

local GroupId = 1141296

repeat wait() until game.Players.LocalPlayer and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:findFirstChild("Head")
local plr = game.Players.LocalPlayer
local head = plr.Character.Head
if plr:IsInGroup(GroupId) then
local gui = Instance.new("BillboardGui", head)
gui.Adornee = head
gui.Size = UDim2.new(100,0,1,0)
gui.StudsOffset = Vector3.new(0,3,0)
gui.Name = "RankGui"
local rank = Instance.new("TextLabel", gui)
rank.Name = "Rank"
rank.BackgroundTransparency = 1
rank.BorderSizePixel = 0
rank.ZIndex = 2
rank.Font = "ArialBold"
rank.Text = plr:GetRoleInGroup(GroupId)
rank.Size = UDim2.new(1,0,1,0)
rank.TextColor3 = Color3.new(1,1,1)
rank.TextStrokeColor3 = Color3.new(0,0,0)
rank.TextStrokeTransparency = 0
rank.TextScaled = true
rank.TextWrapped = false
end

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

Good on ya for attempting to write the code for this. I understand not knowing where to look, and having everyone shouting at you for not knowing how to do it.

Anyway, you can get their rank's name using the GetRoleInGroup method of their Player, with the group ID given as an argument.

Using this, and a table of possible text colors, you can set their text color like so:

-- Put this script in the StarterGui.
-- Then change the GroupId to your Group's Id.

local GroupId = 1141296

local TextColorByRank = {
    "Member" = Color3.new(1, 1, 1),
    "Administrator" = Color3.new(1, 1, 1),
    "Owner" = Color3.new(1, 1, 1),
}

while not Game.Players.LocalPlayer do wait() end
local plr = game.Players.LocalPlayer
local head = plr:WaitForChild("Head")
if plr:IsInGroup(GroupId) then
    local gui = Instance.new("BillboardGui", head)
    gui.Adornee = head
    gui.Size = UDim2.new(100,0,1,0)
    gui.StudsOffset = Vector3.new(0,3,0)
    gui.Name = "RankGui"
    local rank = Instance.new("TextLabel", gui)
    rank.Name = "Rank"
    rank.BackgroundTransparency = 1
    rank.BorderSizePixel = 0
    rank.ZIndex = 2
    rank.Font = "ArialBold"
    rank.Text = plr:GetRoleInGroup(GroupId)
    rank.Size = UDim2.new(1,0,1,0)
    rank.TextColor3 = TextColorByRank[plr:GetRoleInGroup(GroupId)] --The line I changed.
    rank.TextStrokeColor3 = Color3.new(0,0,0)
    rank.TextStrokeTransparency = 0
    rank.TextScaled = true
    rank.TextWrapped = false
end

Do note that this code will break if a player in the group joins with a group name that isn't in the TextColorByRank table. You will have to add checks for that yourself.

0
It doesn't seem to work for me Alpha_Toon 57 — 9y
0
What error are you getting? adark 5487 — 9y
Ad

Answer this question