Overhead gui bug

I have this problem where if the player isn’t in the group, sometimes it doesn’t show their overhead gui. I don’t know how to fix and I’m stuck here. I’m really not sure if it’s the datastore causing this problem or other things.

image

Here’s the script:

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

local OverheadGui = ReplicatedStorage:WaitForChild("OverheadGui")


Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		
		local Humanoid
		local Head
		local LEVEL
		local CloneGui
		local Gradient
		local GradientScript
		local Role
		
		local a, b = pcall(function()
			Humanoid = Character:WaitForChild("Humanoid")
			Head = Character:WaitForChild("Head")

			-- Level for knowing when someone changes
			LEVEL = Player:WaitForChild("StatsFolder"):WaitForChild("Minutes")

			-- Again, this happens regardless of the if statement
			Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None


			CloneGui = OverheadGui:Clone()
			Gradient = CloneGui.Level.UIGradient
			GradientScript = CloneGui.Level.UIScript

			CloneGui.Username.Text = Player.Name.." (@"..Player.DisplayName..")"
			CloneGui.Name = "OverheadGui"
			CloneGui.Parent = Head

			-- Group Role Here
			Role = "- Guest -"
		end)
		
		
		pcall(function()
			Role = Player:GetRoleInGroup(11341797)
		end)
		CloneGui.Rank.Text = Role

		-- Checking To See If Level Changed
		if not b then
			CloneGui.Level.Text = "LEVEL : "..LEVEL.Value
		else
			CloneGui.Level.Text = "ERROR LOADING LEVEL"
		end
		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

I think the culprit behind why the OverheadGui doesn’t show is here. Something prevents the cloning and application of the GUI. Highest probability is on this line:
LEVEL = Player:WaitForChild("StatsFolder"):WaitForChild("Minutes")

Do not chain WaitForChild like this. Try to move into the next line something like this:

local playerStats = Player:WaitForChild("StatsFolder")
LEVEL = Player:WaitForChild("Minutes")

The other possibility could be any of the WaitForChild functions, any of them could have experienced infinite yielding for some reason.

1 Like

I have tested your script, it seems that it didn’t work.
Anyways, thanks for your help.

I tried to look this deeper and kicked around a lot of variables:

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

local OverheadGui = ReplicatedStorage:WaitForChild("OverheadGui")

Players.PlayerAdded:Connect(function(player)
	Player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		local head = character:WaitForChild("Head")
		local playerStats = player:WaitForChild("StatsFolder")
		local playerLevel = playerStats.Minutes
		local cloneGui = OverheadGui:Clone()
		local gradient = cloneGui.Level.UIGradient
		local gradientScript = cloneGui.Level.UIScript
		local role = player:GetRoleInGroup(11341797) or "- Guest -"
		
		humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None

		cloneGui.Username.Text = player.Name.." (@"..player.DisplayName..")"
		cloneGui.Name = "OverheadGui"
		cloneGui.Rank.Text = role
		cloneGui.Level.Text = playerLevel.Value and "LEVEL : " .. playerLevel.Value
		cloneGui.Parent = head
		
		local function getGuiLevelEffect()
			cloneGui.Level.Text = "LEVEL : " .. playerLevel.Value
			if playerLevel.Value >= 100000 then -- Over 100000 Minute LEVEL (RAINBOW)
				cloneGui.Level.TextColor3 = Color3.new(1, 1, 1)
				gradient.Enabled = true
				gradientScript.Disabled = false
			elseif playerLevel.Value >= 10000 then -- Over 10000 Minute LEVEL (DARK RED)
				cloneGui.Level.TextColor3 = Color3.new(0.658824, 0, 0)
			elseif playerLevel.Value >= 5000 then -- Over 5000 Minute LEVEL (ORANGE)
				cloneGui.Level.TextColor3 = Color3.new(1, 0.666667, 0)
			elseif playerLevel.Value >= 1000 then -- Over 1000 Minute LEVEL (BLUE)
				cloneGui.Level.TextColor3 = Color3.new(0, 0.666667, 1)
			elseif playerLevel.Value >= 500 then -- Over 500 Minute LEVEL (PURPLE)
				cloneGui.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
			elseif playerLevel.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
		
		playerLevel.Changed:Connect(getGuiLevelEffect)
		getGuiLevelEffect()
	end)
end)

Oh yeah, speaking of Color3.new, I think you wanted Color3.fromRGB instead, which accepts values between 0 to 255 for each parameter. Other than that, it’s just messy.

Edit: Revised the errors away, apparently multiple variables got typos on themselves. :frowning:

2 Likes

Thank you so much! I used your script and added a head thingy and it works thank you!

1 Like

out of curiosity where is it going

I re-ordered a lot of details on the script. I believe it was because of the order the script originally executed in. If the order was incorrectly done, it may result in whatever the result was above. Especially that pcall is utilized incorrectly; did not print the error message if the pcall wasn’t successful.

1 Like

goes here in this script
image

Ah you meant the script. Remember that the canonical use is ServerScriptService. Always that service, unless there are other dependencies, such as script.Parent being used.