Cloning to character working in studio, but not working in-game?

I’m lost of words right now, someone please save me.

The issue is I’m cloning a billboard gui (OverheadGui) to the player’s head when they join the game. This works with players that are either the Owner of the game, Top Donator, or VIP. But when it comes down to cloning the gui to characters that are none of the above, the script fails to clone the gui, and it shows “infinite yield” error.

THE SCRIPT

--[ SERVICES ]--

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

--[ OVERHEAD LOCALS ]--

local VIPOverheadGui = ReplicatedStorage:WaitForChild("VIPOverheadGui") -- GRABBING THE OVERHEAD GUI's
local OverheadGui = ReplicatedStorage:WaitForChild("OverheadGui")
local OwnerOverheadGui = ReplicatedStorage:WaitForChild("OwnerOverheadGui")
local DonatorOverheadGui = ReplicatedStorage:WaitForChild("DonatorOverheadGui")

--[ GAMEPASS/DONATOR LOCALS ]--

local GamepassId = 1 -- VIP GAMEPASS ID GOES HERE
local GroupId = 1 -- GROUP ID GOES HERE
local Configuration = game.Workspace.Boards.R15Loader.Configuration -- Finding Configuration
local DONATOR_ID = Configuration.userId -- Making Donator ID

--[ MAIN FUNCTIONS ]--

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		local Head = Character:WaitForChild("Head")
		local LEVEL = Player.Minutes
		Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
		
		if Player.Name == "OutlawedPixels" then
			
			local CloneGuiOwner = OwnerOverheadGui:Clone()
			local Gradient = CloneGuiOwner.Level.UIGradient
			local GradientScript = CloneGuiOwner.Level.UIScript
			
			CloneGuiOwner.Username.Text = Player.Name
			CloneGuiOwner.Name = "OverheadGui"
			CloneGuiOwner.Parent = Head
			CloneGuiOwner.Rank.Text = "CHIEF EXECUTIVE"
			
			CloneGuiOwner.Level.Text = "LEVEL : "..LEVEL.Value
			
			LEVEL.Changed:Connect(function()
				CloneGuiOwner.Level.Text = "LEVEL : "..LEVEL.Value
				if LEVEL.Value >= 100000 then
					CloneGuiOwner.Level.TextColor3 = Color3.new(1, 1, 1)
					Gradient.Enabled = true
					GradientScript.Disabled = false
				elseif LEVEL.Value >= 10000 then
					CloneGuiOwner.Level.TextColor3 = Color3.new(0.658824, 0, 0)
				elseif LEVEL.Value >= 5000 then
					CloneGuiOwner.Level.TextColor3 = Color3.new(1, 0.666667, 0)
				elseif LEVEL.Value >= 1000 then
					CloneGuiOwner.Level.TextColor3 = Color3.new(0, 0.666667, 1)
				elseif LEVEL.Value >= 500 then
					CloneGuiOwner.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
				elseif LEVEL.Value >= 100 then
					CloneGuiOwner.Level.TextColor3 = Color3.new(0.333333, 1, 0)
				else
					CloneGuiOwner.Level.TextColor3 = Color3.new(255,255,255)
				end
			end)
			
			if LEVEL.Value >= 100000 then
				CloneGuiOwner.Level.TextColor3 = Color3.new(1, 1, 1)
				Gradient.Enabled = true
				GradientScript.Disabled = false
			elseif LEVEL.Value >= 10000 then
				CloneGuiOwner.Level.TextColor3 = Color3.new(0.658824, 0, 0)
			elseif LEVEL.Value >= 5000 then
				CloneGuiOwner.Level.TextColor3 = Color3.new(1, 0.666667, 0)
			elseif LEVEL.Value >= 1000 then
				CloneGuiOwner.Level.TextColor3 = Color3.new(0, 0.666667, 1)
			elseif LEVEL.Value >= 500 then
				CloneGuiOwner.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
			elseif LEVEL.Value >= 100 then
				CloneGuiOwner.Level.TextColor3 = Color3.new(0.333333, 1, 0)
			else
				CloneGuiOwner.Level.TextColor3 = Color3.new(255,255,255)
			end
			
		-- TOP DONATOR
		elseif Player.UserId == DONATOR_ID.Value then
			
			local DonatorCloneGui = DonatorOverheadGui:Clone()
			local Gradient = DonatorCloneGui.Level.UIGradient
			local GradientScript = DonatorCloneGui.Level.UIScript
			
			DonatorCloneGui.Username.Text = Player.Name
			DonatorCloneGui.Name = "OverheadGui"
			DonatorCloneGui.Parent = Head
			DonatorCloneGui.Rank.Text = "Top Investor"
			
			DonatorCloneGui.Level.Text = "LEVEL : "..LEVEL.Value
			
			LEVEL.Changed:Connect(function()
				DonatorCloneGui.Level.Text = "LEVEL : "..LEVEL.Value
				if LEVEL.Value >= 100000 then
					DonatorCloneGui.Level.TextColor3 = Color3.new(1, 1, 1)
					Gradient.Enabled = true
					GradientScript.Disabled = false
				elseif LEVEL.Value >= 10000 then
					DonatorCloneGui.Level.TextColor3 = Color3.new(0.658824, 0, 0)
				elseif LEVEL.Value >= 5000 then
					DonatorCloneGui.Level.TextColor3 = Color3.new(1, 0.666667, 0)
				elseif LEVEL.Value >= 1000 then
					DonatorCloneGui.Level.TextColor3 = Color3.new(0, 0.666667, 1)
				elseif LEVEL.Value >= 500 then
					DonatorCloneGui.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
				elseif LEVEL.Value >= 100 then
					DonatorCloneGui.Level.TextColor3 = Color3.new(0.333333, 1, 0)
				else
					DonatorCloneGui.Level.TextColor3 = Color3.new(255,255,255)
				end
			end)
			
			if LEVEL.Value >= 100000 then
				DonatorCloneGui.Level.TextColor3 = Color3.new(1, 1, 1)
				Gradient.Enabled = true
				GradientScript.Disabled = false
			elseif LEVEL.Value >= 10000 then
				DonatorCloneGui.Level.TextColor3 = Color3.new(0.658824, 0, 0)
			elseif LEVEL.Value >= 5000 then
				DonatorCloneGui.Level.TextColor3 = Color3.new(1, 0.666667, 0)
			elseif LEVEL.Value >= 1000 then
				DonatorCloneGui.Level.TextColor3 = Color3.new(0, 0.666667, 1)
			elseif LEVEL.Value >= 500 then
				DonatorCloneGui.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
			elseif LEVEL.Value >= 100 then
				DonatorCloneGui.Level.TextColor3 = Color3.new(0.333333, 1, 0)
			else
				DonatorCloneGui.Level.TextColor3 = Color3.new(255,255,255)
			end
			
		-- VIP / MORE RANKS
		elseif MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
			
			local CloneGuiVIP = VIPOverheadGui:Clone()
			local Gradient = CloneGuiVIP.Level.UIGradient
			local GradientScript = CloneGuiVIP.Level.UIScript
			
			CloneGuiVIP.Username.Text = Player.Name
			CloneGuiVIP.Name = "OverheadGui"
			CloneGuiVIP.Parent = Head
			CloneGuiVIP.Username.TextColor3 = Color3.new(0.901961, 0.737255, 0)
			
			local Role = " "
			pcall(function()
				Role = Player:GetRoleInGroup(GroupId)
			end)
			CloneGuiVIP.Rank.Text = Role
			
			CloneGuiVIP.Level.Text = "LEVEL : "..LEVEL.Value
			
			LEVEL.Changed:Connect(function()
				CloneGuiVIP.Level.Text = "LEVEL : "..LEVEL.Value
				if LEVEL.Value >= 100000 then
					CloneGuiVIP.Level.TextColor3 = Color3.new(1, 1, 1)
					Gradient.Enabled = true
					GradientScript.Disabled = false
				elseif LEVEL.Value >= 10000 then
					CloneGuiVIP.Level.TextColor3 = Color3.new(0.658824, 0, 0)
				elseif LEVEL.Value >= 5000 then
					CloneGuiVIP.Level.TextColor3 = Color3.new(1, 0.666667, 0)
				elseif LEVEL.Value >= 1000 then
					CloneGuiVIP.Level.TextColor3 = Color3.new(0, 0.666667, 1)
				elseif LEVEL.Value >= 500 then
					CloneGuiVIP.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
				elseif LEVEL.Value >= 100 then
					CloneGuiVIP.Level.TextColor3 = Color3.new(0.333333, 1, 0)
				else
					CloneGuiVIP.Level.TextColor3 = Color3.new(255,255,255)
				end
			end)
			
			if LEVEL.Value >= 100000 then
				CloneGuiVIP.Level.TextColor3 = Color3.new(1, 1, 1)
				Gradient.Enabled = true
				GradientScript.Disabled = false
			elseif LEVEL.Value >= 10000 then
				CloneGuiVIP.Level.TextColor3 = Color3.new(0.658824, 0, 0)
			elseif LEVEL.Value >= 5000 then
				CloneGuiVIP.Level.TextColor3 = Color3.new(1, 0.666667, 0)
			elseif LEVEL.Value >= 1000 then
				CloneGuiVIP.Level.TextColor3 = Color3.new(0, 0.666667, 1)
			elseif LEVEL.Value >= 500 then
				CloneGuiVIP.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
			elseif LEVEL.Value >= 100 then
				CloneGuiVIP.Level.TextColor3 = Color3.new(0.333333, 1, 0)
			else
				CloneGuiVIP.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
			CloneGui.Name = "OverheadGui"
			CloneGui.Parent = Head
			
			local Role = "- Guest -"
			pcall(function()
				Role = Player:GetRoleInGroup(GroupId)
			end)
			CloneGui.Rank.Text = Role
			
			CloneGui.Level.Text = "LEVEL : "..LEVEL.Value
			
			LEVEL.Changed:Connect(function()
				CloneGui.Level.Text = "LEVEL : "..LEVEL.Value
				if LEVEL.Value >= 100000 then
					CloneGui.Level.TextColor3 = Color3.new(1, 1, 1)
					Gradient.Enabled = true
					GradientScript.Disabled = false
				elseif LEVEL.Value >= 10000 then
					CloneGui.Level.TextColor3 = Color3.new(0.658824, 0, 0)
				elseif LEVEL.Value >= 5000 then 
					CloneGui.Level.TextColor3 = Color3.new(1, 0.666667, 0)
				elseif LEVEL.Value >= 1000 then
					CloneGui.Level.TextColor3 = Color3.new(0, 0.666667, 1)
				elseif LEVEL.Value >= 500 then
					CloneGui.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
				elseif LEVEL.Value >= 100 then
					CloneGui.Level.TextColor3 = Color3.new(0.333333, 1, 0)
				else
					CloneGui.Level.TextColor3 = Color3.new(255,255,255)
				end
			end)
			
			if LEVEL.Value >= 100000 then
				CloneGui.Level.TextColor3 = Color3.new(1, 1, 1)
				Gradient.Enabled = true
				GradientScript.Disabled = false
			elseif LEVEL.Value >= 10000 then
				CloneGui.Level.TextColor3 = Color3.new(0.658824, 0, 0)
			elseif LEVEL.Value >= 5000 then
				CloneGui.Level.TextColor3 = Color3.new(1, 0.666667, 0)
			elseif LEVEL.Value >= 1000 then
				CloneGui.Level.TextColor3 = Color3.new(0, 0.666667, 1)
			elseif LEVEL.Value >= 500 then
				CloneGui.Level.TextColor3 = Color3.new(0.85098, 0.00784314, 1)
			elseif LEVEL.Value >= 100 then
				CloneGui.Level.TextColor3 = Color3.new(0.333333, 1, 0)
			else
				CloneGui.Level.TextColor3 = Color3.new(255,255,255)
			end
		end
	end)
end)

WORKING IN STUDIO (FOR THE “GUEST” PLAYERS)

WORKING IN-GAME FOR OWNER, BUT NOT FOR “GUEST” PLAYER

ERROR MESSAGE IN-GAME

HIERARACHY/GAME SETUP

Any help is greatly appreciated, I’m am stuck on this final and last problem for my game until it can be fully released. If you need any more information or photos, I will be more than happy to get it to you. Thank you!

Quick edit: Don’t worry about group and gamepass ID’s, they are not put in on purpose. I can assure you they are not part of the problem.

1 Like

Had you made sure that the Billboard GUI is cloned to the character’s head?

1 Like

Yes, it clones to the character’s head in Studio, but not in game, and I don’t know why.

If you’re still facing this, U can use CharacterAppearanceLoaded or wait()
Put it before you’re cloning the nametag.

Hey there fellow developer :wave: !

I recently faced a similar issue with my game, so hopefully this suggestion might help solve yours, too.
Try adding the line:

repeat wait() until Character:FindFirstChild(“Head”)

…before the line:

local Head = Character:WaitForChild(“Head”)

Sorry if this response layout is confusing. It’s my first time attempting to write a comment on the forum.
I wish you luck with your game! :grin: :+1: