I need help with GetRoleInGroup script

So basically, I was making a overhead gui for my game. The problem was that, when the user was not in the group, it wouldn’t show up the overhead gui for them.
image

			local CloneGui = OverheadGui:Clone()
			local Gradient = CloneGui.Level.UIGradient
			local GradientScript = CloneGui.Level.UIScript
			
			CloneGui.Username.Text = Player.Name.." (@"..Player.DisplayName..")"
			CloneGui.Name = "OverheadGui"
			CloneGui.Parent = Head
			
			-- Group Role Here
			local Role = "- Guest -"
			pcall(function()
				Role = Player:GetRoleInGroup(9997169)
			end)
			CloneGui.Rank.Text = Role
			
			

Please help!

1 Like

Can you show more of the code? Also did you try adding the person to the group then seeing if you could see their tag? Their tag should be “Guest” if they are not in the group. Maybe you’re accidently using a LocalScript to do this? You should post more context.

There:

		local CloneGui = OverheadGui:Clone()
		local Gradient = CloneGui.Level.UIGradient
		local GradientScript = CloneGui.Level.UIScript
		
		CloneGui.Username.Text = Player.Name.." (@"..Player.DisplayName..")"
		CloneGui.Name = "OverheadGui"
		CloneGui.Parent = Head
		
		-- Group Role Here
		local Role = "- Guest -"
		pcall(function()
			Role = Player:GetRoleInGroup(9997169)
		end)
		CloneGui.Rank.Text = Role
		
		-- Level Rank Here
		CloneGui.Level.Text = "LEVEL : "..LEVEL.Value
		
		-- Checking To See If Level Changed
		LEVEL.Changed:Connect(function()
			CloneGui.Level.Text = "LEVEL : "..LEVEL.Value
			if LEVEL.Value >= 100000 then -- Over 100000 Minute LEVEL (RAINBOW)
				CloneGui.Level.TextColor3 = Color3.new(1, 1, 1)
				Gradient.Enabled = true
				GradientScript.Disabled = false
			elseif LEVEL.Value >= 10000 then -- Over 10000 Minute LEVEL (DARK RED)
				CloneGui.Level.TextColor3 = Color3.new(0.658824, 0, 0)
			elseif LEVEL.Value >= 5000 then -- Over 5000 Minute LEVEL (ORANGE)
				CloneGui.Level.TextColor3 = Color3.new(1, 0.666667, 0)
			elseif LEVEL.Value >= 1000 then -- Over 1000 Minute LEVEL (BLUE)
				CloneGui.Level.TextColor3 = Color3.new(0, 0.666667, 1)
			elseif LEVEL.Value >= 500 then -- Over 500 Minute LEVEL (PURPLE)
				CloneGui.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
			elseif LEVEL.Value >= 100 then -- Over 100 Minute LEVEL (GREEN)
				CloneGui.Level.TextColor3 = Color3.new(0.333333, 1, 0)
			else  -- DEFAULT LEVEL (WHITE)
				CloneGui.Level.TextColor3 = Color3.new(255,255,255)
			end
		end)
		
		if LEVEL.Value >= 100000 then -- Over 100000 Minute LEVEL (RAINBOW)
			CloneGui.Level.TextColor3 = Color3.new(1, 1, 1)
			Gradient.Enabled = true
			GradientScript.Disabled = false
		elseif LEVEL.Value >= 10000 then -- Over 10000 Minute LEVEL (DARK RED)
			CloneGui.Level.TextColor3 = Color3.new(0.658824, 0, 0)
		elseif LEVEL.Value >= 5000 then -- Over 5000 Minute LEVEL (ORANGE)
			CloneGui.Level.TextColor3 = Color3.new(1, 0.666667, 0)
		elseif LEVEL.Value >= 1000 then -- Over 1000 Minute LEVEL (BLUE)
			CloneGui.Level.TextColor3 = Color3.new(0, 0.666667, 1)
		elseif LEVEL.Value >= 500 then -- Over 500 Minute LEVEL (PURPLE)
			CloneGui.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
		elseif LEVEL.Value >= 100 then -- Over 100 Minute LEVEL (GREEN)
			CloneGui.Level.TextColor3 = Color3.new(0.333333, 1, 0)
		else  -- DEFAULT LEVEL (WHITE)
			CloneGui.Level.TextColor3 = Color3.new(255,255,255)
		end
	end
end)

end)

Do you have any errors in your output?

Maybe use a table with all the colors instead of doing this, it’s pretty messy.

1 Like

Can you post the code above is what I meant. I want to know what is above local CloneGui = OverheadGui:Clone()

nope nothing.

Check on the server instead.
(max char)

image

You’re viewing the Client log instead of the Server log so that makes me suspicious that you’re using a LocalScript. Can you please tell me what type of script you are using and post the code I wanted to see.

It’s a normal script.

And that’s the entire script in the script.

–[ SERVICES ]–

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local Players = game:GetService(“Players”)

–[ OVERHEAD LOCALS ]–

local OverheadGui = ReplicatedStorage:WaitForChild(“OverheadGui”)
local OwnerOverheadGui = ReplicatedStorage:WaitForChild(“OwnerOverheadGui”)

–[ MAIN FUNCTIONS ]–

Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
– These variables are used regardless of whether the user owns the gamepass or not
– so we can define them outside the if statement
local Humanoid = Character:WaitForChild(“Humanoid”)
local Head = Character:WaitForChild(“Head”)

	-- Level for knowing when someone changes
	local LEVEL = Player.Minutes
	
	-- Again, this happens regardless of the if statement
	Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	
	-- Owner Name
	if Player.Name == "IdealBoard" then
		
		local CloneGuiOwner = OwnerOverheadGui:Clone()
		local Gradient = CloneGuiOwner.Level.UIGradient
		local GradientScript = CloneGuiOwner.Level.UIScript
		
		CloneGuiOwner.Username.Text = Player.Name.." (@"..Player.DisplayName..")"
		CloneGuiOwner.Name = "OverheadGui"
		CloneGuiOwner.Parent = Head
		CloneGuiOwner.Rank.Text = ""
		
		-- Level Rank Here
		CloneGuiOwner.Level.Text = "LEVEL : "..LEVEL.Value
		
		-- Checking To See If Level Changed
		LEVEL.Changed:Connect(function()
			CloneGuiOwner.Level.Text = "LEVEL : "..LEVEL.Value
			if LEVEL.Value >= 100000 then -- Over 100000 Minute LEVEL (RAINBOW)
				CloneGuiOwner.Level.TextColor3 = Color3.new(1, 1, 1)
				Gradient.Enabled = true
				GradientScript.Disabled = false
			elseif LEVEL.Value >= 10000 then -- Over 10000 Minute LEVEL (DARK RED)
				CloneGuiOwner.Level.TextColor3 = Color3.new(0.658824, 0, 0)
			elseif LEVEL.Value >= 5000 then -- Over 5000 Minute LEVEL (ORANGE)
				CloneGuiOwner.Level.TextColor3 = Color3.new(1, 0.666667, 0)
			elseif LEVEL.Value >= 1000 then -- Over 1000 Minute LEVEL (BLUE)
				CloneGuiOwner.Level.TextColor3 = Color3.new(0, 0.666667, 1)
			elseif LEVEL.Value >= 500 then -- Over 500 Minute LEVEL (PURPLE)
				CloneGuiOwner.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
			elseif LEVEL.Value >= 100 then -- Over 100 Minute LEVEL (GREEN)
				CloneGuiOwner.Level.TextColor3 = Color3.new(0.333333, 1, 0)
			else  -- DEFAULT LEVEL (WHITE)
				CloneGuiOwner.Level.TextColor3 = Color3.new(255,255,255)
			end
		end)
		
		if LEVEL.Value >= 100000 then -- Over 100000 Minute LEVEL (RAINBOW)
			CloneGuiOwner.Level.TextColor3 = Color3.new(1, 1, 1)
			Gradient.Enabled = true
			GradientScript.Disabled = false
		elseif LEVEL.Value >= 10000 then -- Over 10000 Minute LEVEL (DARK RED)
			CloneGuiOwner.Level.TextColor3 = Color3.new(0.658824, 0, 0)
		elseif LEVEL.Value >= 5000 then -- Over 5000 Minute LEVEL (ORANGE)
			CloneGuiOwner.Level.TextColor3 = Color3.new(1, 0.666667, 0)
		elseif LEVEL.Value >= 1000 then -- Over 1000 Minute LEVEL (BLUE)
			CloneGuiOwner.Level.TextColor3 = Color3.new(0, 0.666667, 1)
		elseif LEVEL.Value >= 500 then -- Over 500 Minute LEVEL (PURPLE)
			CloneGuiOwner.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
		elseif LEVEL.Value >= 100 then -- Over 100 Minute LEVEL (GREEN)
			CloneGuiOwner.Level.TextColor3 = Color3.new(0.333333, 1, 0)
		else  -- DEFAULT LEVEL (WHITE)
			CloneGuiOwner.Level.TextColor3 = Color3.new(255,255,255)
		end
		

	

		-- Different / Default Overhead
		local CloneGui = OverheadGui:Clone()
		local Gradient = CloneGui.Level.UIGradient
		local GradientScript = CloneGui.Level.UIScript
		
		CloneGui.Username.Text = Player.Name.." (@"..Player.DisplayName..")"
		CloneGui.Name = "OverheadGui"
		CloneGui.Parent = Head
		
		-- Group Role Here
		local Role = "- Guest -"
		pcall(function()
			Role = Player:GetRoleInGroup(9997169)
		end)
		CloneGui.Rank.Text = Role
		
		-- Level Rank Here
		CloneGui.Level.Text = "LEVEL : "..LEVEL.Value
		
		-- Checking To See If Level Changed
		LEVEL.Changed:Connect(function()
			CloneGui.Level.Text = "LEVEL : "..LEVEL.Value
			if LEVEL.Value >= 100000 then -- Over 100000 Minute LEVEL (RAINBOW)
				CloneGui.Level.TextColor3 = Color3.new(1, 1, 1)
				Gradient.Enabled = true
				GradientScript.Disabled = false
			elseif LEVEL.Value >= 10000 then -- Over 10000 Minute LEVEL (DARK RED)
				CloneGui.Level.TextColor3 = Color3.new(0.658824, 0, 0)
			elseif LEVEL.Value >= 5000 then -- Over 5000 Minute LEVEL (ORANGE)
				CloneGui.Level.TextColor3 = Color3.new(1, 0.666667, 0)
			elseif LEVEL.Value >= 1000 then -- Over 1000 Minute LEVEL (BLUE)
				CloneGui.Level.TextColor3 = Color3.new(0, 0.666667, 1)
			elseif LEVEL.Value >= 500 then -- Over 500 Minute LEVEL (PURPLE)
				CloneGui.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
			elseif LEVEL.Value >= 100 then -- Over 100 Minute LEVEL (GREEN)
				CloneGui.Level.TextColor3 = Color3.new(0.333333, 1, 0)
			else  -- DEFAULT LEVEL (WHITE)
				CloneGui.Level.TextColor3 = Color3.new(255,255,255)
			end
		end)
		
		if LEVEL.Value >= 100000 then -- Over 100000 Minute LEVEL (RAINBOW)
			CloneGui.Level.TextColor3 = Color3.new(1, 1, 1)
			Gradient.Enabled = true
			GradientScript.Disabled = false
		elseif LEVEL.Value >= 10000 then -- Over 10000 Minute LEVEL (DARK RED)
			CloneGui.Level.TextColor3 = Color3.new(0.658824, 0, 0)
		elseif LEVEL.Value >= 5000 then -- Over 5000 Minute LEVEL (ORANGE)
			CloneGui.Level.TextColor3 = Color3.new(1, 0.666667, 0)
		elseif LEVEL.Value >= 1000 then -- Over 1000 Minute LEVEL (BLUE)
			CloneGui.Level.TextColor3 = Color3.new(0, 0.666667, 1)
		elseif LEVEL.Value >= 500 then -- Over 500 Minute LEVEL (PURPLE)
			CloneGui.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
		elseif LEVEL.Value >= 100 then -- Over 100 Minute LEVEL (GREEN)
			CloneGui.Level.TextColor3 = Color3.new(0.333333, 1, 0)
		else  -- DEFAULT LEVEL (WHITE)
			CloneGui.Level.TextColor3 = Color3.new(255,255,255)
		end
	end
end)

You’re checking if they’re you. Remove this if statement. I think you have an end at the wrong place or your indentation is weird and I am mistaken.

3 Likes

Thank you, I will try and then I’ll tell you if it works or not.

It should. So try this. I rearranged the code a bit so that there is an else statement.

--[ SERVICES ]--

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

--[ OVERHEAD LOCALS ]--

local OverheadGui = ReplicatedStorage:WaitForChild("OverheadGui")
local OwnerOverheadGui = ReplicatedStorage:WaitForChild("OwnerOverheadGui")

--[ MAIN FUNCTIONS ]--

Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
-- These variables are used regardless of whether the user owns the gamepass or not
-- so we can define them outside the if statement
local Humanoid = Character:WaitForChild("Humanoid")
local Head = Character:WaitForChild("Head")

	-- Level for knowing when someone changes
	local LEVEL = Player.Minutes
	
	-- Again, this happens regardless of the if statement
	Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	
	-- Owner Name
	if Player.Name == "IdealBoard" then
		
		local CloneGuiOwner = OwnerOverheadGui:Clone()
		local Gradient = CloneGuiOwner.Level.UIGradient
		local GradientScript = CloneGuiOwner.Level.UIScript
		
		CloneGuiOwner.Username.Text = Player.Name.." (@"..Player.DisplayName..")"
		CloneGuiOwner.Name = "OverheadGui"
		CloneGuiOwner.Parent = Head
		CloneGuiOwner.Rank.Text = ""
		
		-- Level Rank Here
		CloneGuiOwner.Level.Text = "LEVEL : "..LEVEL.Value
		
		-- Checking To See If Level Changed
		LEVEL.Changed:Connect(function()
			CloneGuiOwner.Level.Text = "LEVEL : "..LEVEL.Value
			if LEVEL.Value >= 100000 then -- Over 100000 Minute LEVEL (RAINBOW)
				CloneGuiOwner.Level.TextColor3 = Color3.new(1, 1, 1)
				Gradient.Enabled = true
				GradientScript.Disabled = false
			elseif LEVEL.Value >= 10000 then -- Over 10000 Minute LEVEL (DARK RED)
				CloneGuiOwner.Level.TextColor3 = Color3.new(0.658824, 0, 0)
			elseif LEVEL.Value >= 5000 then -- Over 5000 Minute LEVEL (ORANGE)
				CloneGuiOwner.Level.TextColor3 = Color3.new(1, 0.666667, 0)
			elseif LEVEL.Value >= 1000 then -- Over 1000 Minute LEVEL (BLUE)
				CloneGuiOwner.Level.TextColor3 = Color3.new(0, 0.666667, 1)
			elseif LEVEL.Value >= 500 then -- Over 500 Minute LEVEL (PURPLE)
				CloneGuiOwner.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
			elseif LEVEL.Value >= 100 then -- Over 100 Minute LEVEL (GREEN)
				CloneGuiOwner.Level.TextColor3 = Color3.new(0.333333, 1, 0)
			else  -- DEFAULT LEVEL (WHITE)
				CloneGuiOwner.Level.TextColor3 = Color3.new(255,255,255)
			end
		end)
		
		if LEVEL.Value >= 100000 then -- Over 100000 Minute LEVEL (RAINBOW)
			CloneGuiOwner.Level.TextColor3 = Color3.new(1, 1, 1)
			Gradient.Enabled = true
			GradientScript.Disabled = false
		elseif LEVEL.Value >= 10000 then -- Over 10000 Minute LEVEL (DARK RED)
			CloneGuiOwner.Level.TextColor3 = Color3.new(0.658824, 0, 0)
		elseif LEVEL.Value >= 5000 then -- Over 5000 Minute LEVEL (ORANGE)
			CloneGuiOwner.Level.TextColor3 = Color3.new(1, 0.666667, 0)
		elseif LEVEL.Value >= 1000 then -- Over 1000 Minute LEVEL (BLUE)
			CloneGuiOwner.Level.TextColor3 = Color3.new(0, 0.666667, 1)
		elseif LEVEL.Value >= 500 then -- Over 500 Minute LEVEL (PURPLE)
			CloneGuiOwner.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
		elseif LEVEL.Value >= 100 then -- Over 100 Minute LEVEL (GREEN)
			CloneGuiOwner.Level.TextColor3 = Color3.new(0.333333, 1, 0)
		else  -- DEFAULT LEVEL (WHITE)
			CloneGuiOwner.Level.TextColor3 = Color3.new(255,255,255)
		end
	else
		-- Different / Default Overhead
		local CloneGui = OverheadGui:Clone()
		local Gradient = CloneGui.Level.UIGradient
		local GradientScript = CloneGui.Level.UIScript
		
		CloneGui.Username.Text = Player.Name.." (@"..Player.DisplayName..")"
		CloneGui.Name = "OverheadGui"
		CloneGui.Parent = Head
		
		-- Group Role Here
		local Role = "- Guest -"
		pcall(function()
			Role = Player:GetRoleInGroup(9997169)
		end)
		CloneGui.Rank.Text = Role
		
		-- Level Rank Here
		CloneGui.Level.Text = "LEVEL : "..LEVEL.Value
		
		-- Checking To See If Level Changed
		LEVEL.Changed:Connect(function()
			CloneGui.Level.Text = "LEVEL : "..LEVEL.Value
			if LEVEL.Value >= 100000 then -- Over 100000 Minute LEVEL (RAINBOW)
				CloneGui.Level.TextColor3 = Color3.new(1, 1, 1)
				Gradient.Enabled = true
				GradientScript.Disabled = false
			elseif LEVEL.Value >= 10000 then -- Over 10000 Minute LEVEL (DARK RED)
				CloneGui.Level.TextColor3 = Color3.new(0.658824, 0, 0)
			elseif LEVEL.Value >= 5000 then -- Over 5000 Minute LEVEL (ORANGE)
				CloneGui.Level.TextColor3 = Color3.new(1, 0.666667, 0)
			elseif LEVEL.Value >= 1000 then -- Over 1000 Minute LEVEL (BLUE)
				CloneGui.Level.TextColor3 = Color3.new(0, 0.666667, 1)
			elseif LEVEL.Value >= 500 then -- Over 500 Minute LEVEL (PURPLE)
				CloneGui.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
			elseif LEVEL.Value >= 100 then -- Over 100 Minute LEVEL (GREEN)
				CloneGui.Level.TextColor3 = Color3.new(0.333333, 1, 0)
			else  -- DEFAULT LEVEL (WHITE)
				CloneGui.Level.TextColor3 = Color3.new(255,255,255)
			end
		end)
		
		if LEVEL.Value >= 100000 then -- Over 100000 Minute LEVEL (RAINBOW)
			CloneGui.Level.TextColor3 = Color3.new(1, 1, 1)
			Gradient.Enabled = true
			GradientScript.Disabled = false
		elseif LEVEL.Value >= 10000 then -- Over 10000 Minute LEVEL (DARK RED)
			CloneGui.Level.TextColor3 = Color3.new(0.658824, 0, 0)
		elseif LEVEL.Value >= 5000 then -- Over 5000 Minute LEVEL (ORANGE)
			CloneGui.Level.TextColor3 = Color3.new(1, 0.666667, 0)
		elseif LEVEL.Value >= 1000 then -- Over 1000 Minute LEVEL (BLUE)
			CloneGui.Level.TextColor3 = Color3.new(0, 0.666667, 1)
		elseif LEVEL.Value >= 500 then -- Over 500 Minute LEVEL (PURPLE)
			CloneGui.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
		elseif LEVEL.Value >= 100 then -- Over 100 Minute LEVEL (GREEN)
			CloneGui.Level.TextColor3 = Color3.new(0.333333, 1, 0)
		else  -- DEFAULT LEVEL (WHITE)
			CloneGui.Level.TextColor3 = Color3.new(255,255,255)
		end
	end
end)
1 Like

That works!

But the group rank disappeared for some reason.
image

Like andrew said, if the ranks and roles are already defined I don’t see the purpose in checking the player name? I would just leave it as ‘if Player then’. Or you could just add a check
“if Player:IsInGroup(9997169) then”

1 Like