So I did a color for particular role overhead gui script can some one help me fix it, the color for role is not working its white still

So here is the script for the overhead GUI the color on overhead isn’t working can some one help me fix it, thank you.

local groupId = 12488072
local AFKEvent = game.ReplicatedStorage:FindFirstChild("AFK")
local rank1number = 1
local rank1color = Color3.fromRGB(255, 0, 191)
local rank2number = 2
local rank2color = Color3.fromRGB(255, 0, 191)
local rank3number = 3
local rank3color = Color3.fromRGB(98, 37, 209)
local rank4number = 4
local rank4color = Color3.fromRGB(98, 37, 209)
local rank5number = 5
local rank5color = Color3.fromRGB(98, 37, 209)
local rank6number = 6
local rank6color = Color3.fromRGB(98, 37, 209)
local rank7number = 7
local rank7color = Color3.fromRGB(98, 37, 209)
local rank8Anumber = 8
local rank8Acolor = Color3.fromRGB(98, 37, 209)
local rank8Bnumber = 8
local rank8Bcolor = Color3.fromRGB(98, 37, 209)
local rank9Anumber = 8
local rank9Acolor = Color3.fromRGB(98, 37, 209)
local rank9Bnumber = 8
local rank9Bcolor = Color3.fromRGB(98, 37, 209)
local rank10number = 9
local rank10color = Color3.fromRGB(0, 32, 96)
local rank11number = 11
local rank11color = Color3.fromRGB(175, 148, 131)
local rank12number = 12
local rank12color = Color3.fromRGB(175, 148, 131)
local rank13number = 13
local rank13color = Color3.fromRGB(175, 148, 131)
local rank14number = 14
local rank14color = Color3.fromRGB(175, 148, 131)
local rank15number = 15
local rank15color = Color3.fromRGB(108, 88, 75)
local rank16number = 16
local rank16color = Color3.fromRGB(108, 88, 75)
local rank17number = 17
local rank17color = Color3.fromRGB(108, 88, 75)
local rank18number = 18
local rank18color = Color3.fromRGB(239, 184, 56)
local rank255number = 255
local rank255color = Color3.fromRGB(239, 184, 56)

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local GuiClone = script.OverheadGui:Clone()
		GuiClone.Parent = Character.Head
		local namelabel = GuiClone
		local ranklabel = GuiClone.Rank
		local usernamelabel = GuiClone.Username
		local PlayerRank = Player:GetRoleInGroup(groupId)
		usernamelabel.Text = Player.Name
		ranklabel.Text = PlayerRank
		local Role = "Guest"
		game.Players.PlayerAdded:Connect(function(plr)
			if plr:GetRankInGroup(groupId) == rank1number then
				ranklabel.TextColor3 = rank1color
			elseif plr:GetRankInGroup(groupId) == rank2number then
				ranklabel.TextColor3 = rank2color
			elseif plr:GetRankInGroup(groupId) == rank3number then
				ranklabel.TextColor3 = rank3color
			elseif plr:GetRankInGroup(groupId) == rank4number then
				ranklabel.TextColor3 = rank4color
			elseif plr:GetRankInGroup(groupId) == rank5number then
				ranklabel.TextColor3 = rank5color
			elseif plr:GetRankInGroup(groupId) == rank6number then
				ranklabel.TextColor3 = rank6color
			elseif plr:GetRankInGroup(groupId) == rank7number then
				ranklabel.TextColor3 = rank7color
			elseif plr:GetRankInGroup(groupId) == rank8Anumber then
				ranklabel.TextColor3 = rank8Acolor
			elseif plr:GetRankInGroup(groupId) == rank8Bnumber then
				ranklabel.TextColor3 = rank8Bcolor
			elseif plr:GetRankInGroup(groupId) == rank9Anumber then
				ranklabel.TextColor3 = rank9Acolor
			elseif plr:GetRankInGroup(groupId) == rank9Bnumber then
				ranklabel.TextColor3 = rank9Bcolor
			elseif plr:GetRankInGroup(groupId) == rank10number then
				ranklabel.TextColor3 = rank10color
			elseif plr:GetRankInGroup(groupId) == rank11number then
				ranklabel.TextColor3 = rank11color
			elseif plr:GetRankInGroup(groupId) == rank12number then
				ranklabel.TextColor3 = rank12color
			elseif plr:GetRankInGroup(groupId) == rank13number then
				ranklabel.TextColor3 = rank13color
			elseif plr:GetRankInGroup(groupId) == rank14number then
				ranklabel.TextColor3 = rank14color
			elseif plr:GetRankInGroup(groupId) == rank15number then
				ranklabel.TextColor3 = rank15color
			elseif plr:GetRankInGroup(groupId) == rank16number then
				ranklabel.TextColor3 = rank16color
			elseif plr:GetRankInGroup(groupId) == rank17number then
				ranklabel.TextColor3 = rank17color
			elseif plr:GetRankInGroup(groupId) == rank18number then
				ranklabel.TextColor3 = rank18color
			elseif plr:GetRankInGroup(groupId) == rank255number then
				ranklabel.TextColor3 = rank255color
			end
		end)
		pcall(function()
			Role = Player:GetRoleInGroup(groupId)
		end)
	end)
end)

Are there any errors? If so, could you send a screen shot

1 Like

there wasnt any errors on the script the output didnt come properly

I think it may be that you’ve created a player added function inside of a character added function. Try something like this:

local GroupID = 12488072

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local GuiClone = script.OverheadGui:Clone()
		GuiClone.Parent = Character.Head
		local RankLabel = GuiClone.Rank
		local UsernameLabel = GuiClone.Username
		local PlayerRank = Player:GetRoleInGroup(GroupID)
		UsernameLabel.Text = Player.Name
		RankLabel.Text = PlayerRank
		if Player:GetRankInGroup(GroupID) == 1 then
			RankLabel.TextColor3 = Color3.fromRGB(255, 0, 191)
		elseif Player:GetRankInGroup(GroupID) == 2 then
			RankLabel.TextColor3 = Color3.fromRGB(255, 0, 191)
		end
		-- .....
	end)
end)
1 Like

Alright lemme try it out and tell

where is the script btw its just few lines

Let me rescript your code. Hang on.

1 Like

Alright thank you so much ill wait

See if this works. Change the colours as you wish.

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local GuiClone = script.OverheadGui:Clone()
		GuiClone.Parent = Character.Head
		local RankLabel = GuiClone.Rank
		GuiClone.Username.Text = Player.Name
		local PlayerRank = Player:GetRoleInGroup(12488072)
		RankLabel.Text = PlayerRank
		if PlayerRank == 1 then
			RankLabel.TextColor3 = Color3.fromRGB(255, 0, 191)
		elseif PlayerRank == 2 then
			RankLabel.TextColor3 = Color3.fromRGB(255, 0, 191)
		elseif PlayerRank == 3 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 4 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 5 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 6 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 7 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 8 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 9 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 10 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 11 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 12 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 13 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 14 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 15 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 16 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 17 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 18 then
			RankLabel.TextColor3 = Color3.fromRGB(98, 37, 209)
		elseif PlayerRank == 255 then
			RankLabel.TextColor3 = Color3.fromRGB(239, 184, 56)
		end
	end)
end)

Sorry it doesn’t still work the overhead gui color is still white

I assume the error occurs due to the nested PlayerAdded connection, because that event wont fire twice when a user joins the game, and will probably misbehave if another user joins. I fixed the issue and cleaned the code snippet using tables to make it more readable:

--Script inside StarterCharacterScripts(runs everytime a character spawns, inside that character)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players") 

--use dictionaries/arrays instead of huge if statements when possible
--[rank] = color
local colors = {
	[1] = Color3.fromRGB(255, 0, 191),
	[2] = Color3.fromRGB(255, 0, 191),
	[3] = Color3.fromRGB(98, 37, 209),
	[4] = Color3.fromRGB(98, 37, 209),
	[5] = Color3.fromRGB(98, 37, 209),
	[6] = Color3.fromRGB(98, 37, 209),
	[7] = Color3.fromRGB(98, 37, 209),
	[8] = Color3.fromRGB(98, 37, 209),
	[9] = Color3.fromRGB(98, 37, 209),
	[10] = Color3.fromRGB(0, 32, 209),
	[11] = Color3.fromRGB(175, 148, 131),
	[12] = Color3.fromRGB(175, 148, 131),
	[13] = Color3.fromRGB(175, 148, 131),
	[14] = Color3.fromRGB(175, 148, 131),
	[15] = Color3.fromRGB(108, 88, 75),
	[16] = Color3.fromRGB(108, 88, 75),
	[17] = Color3.fromRGB(108, 88, 75),
	[18] = Color3.fromRGB(239, 184, 56),
	[255] = Color3.fromRGB(239, 184, 56)
}

local groupId = 12488072
local AFKEvent = ReplicatedStorage:WaitForChild("AFK")

--script.Parent is the Character because of the script location
local Character = script.Parent 
local Player = Players:GetPlayerFromCharacter(Character)

local namelabel = script.OverheadGui:Clone() 
namelabel.Parent = Character:WaitForChild("Head") 
local ranklabel = namelabel.Rank 
namelabel.Username.Text = Player.Name 

local Rank = Player:GetRankInGroup(groupId)
local Role = Player:GetRoleInGroup(groupId)
local Color = colors[Rank] 

ranklabel.Text = Role 
if Color then
	ranklabel.TextColor3 = Color 
end
1 Like

can u make it as a whole script im new to scripting so this is confusing sorry for disturbing alot but i dont get it so can you make it as a model or some thing so i can copy paste it please?

Where is the script located? My script should work.

serverscriptstorage it is located there.

You just need to replace the script code and change its location to game>StarterPlayer>StarterCharacterScripts.

1 Like

is it local script or normal script?

It’s a normal script as noted on the top.
PS: Make sure to keep the OverheadGui inside the script

1 Like

btw it is not working
the gui is not even in head

Would you send the file? I will fix it for you if you want

1 Like

Ye sure like rbxl file can i send?