Script is processing gui before loading

Hey devs,

I am currently working on a game and it supports PC & mobile, when a player joins the game either on mobile or PC, a script gets a gui from replicatedstorage and parents it to PlayerGui.

The problem is that some of the scripts from Serverscriptservice attempt to detect the gui from mobile or PC before the script that parents the guis actually begins.

How can I fix this?

Help is appreciated!

You should use :WaitForChild(“GuiName”) so the script waits for the gui to load

2 Likes

Alright i’ll go ahead and try that.

Unfortunately this did not work for me, any other possible solutions?

Can you send the script and the error because it should work

Wait now that I re-read what you said, why didn’t you put the gui in startergui

Here is the script that runs to early, this is located in ServerScriptService

local mps = game:GetService("MarketplaceService")
local gamepassid = 21391533


game.Players.PlayerAdded:Connect(function(player)
	if mps:UserOwnsGamePassAsync(player.UserId, gamepassid) then
		script.shop:Clone().Parent = player.PlayerGui:WaitForChild("MainGui").Background
		
		script.exclusive:Clone().Parent = player.PlayerGui:WaitForChild("MainGui").Background.Shop.Frame
	else
		script.button:Clone().Parent = player.PlayerGui:WaitForChild("MainGui").Background.Shop.Frame
		
	end
end)


game.ReplicatedStorage.GuiPurchasedEXCLUSIVE.OnServerEvent:Connect(function(player)
	script.shop:Clone().Parent = player.PlayerGui:WaitForChild("MainGui").Background
	script.exclusive:Clone().Parent = player.PlayerGui:WaitForChild("MainGui").Background.Shop.Frame
end)

There is another script that parents the “MainGui” to the PlayerGui.

Maybe you could make a variable in both of the functions called maingui and you it is the gui. Kinda like

local main gui = player.PlayerGui:WaitForChild(“MainGui”)

Other than that I’m not sure

1 Like

This did not work for me either, anyone’s help is still appreciated.

Is this in a server script? If so, try doing this:

player:WaitForChild("PlayerGui")
2 Likes

Alright, i’ll go try this now…

Hey @synical4, the script did not work for me. Is there anything else I can do?

local mps = game:GetService("MarketplaceService")
local gamepassid = 21391563


game.Players.PlayerAdded:Connect(function(player)
	if mps:UserOwnsGamePassAsync(player.UserId, gamepassid) then
		script.ShopExclusive:Clone().Parent = player:WaitForChild("PlayerGui"):WaitForChild("MainGui").Background
		
		script.ExclusiveButton:Clone().Parent = player:WaitForChild("PlayerGui"):WaitForChild("MainGui").Background.Shop.Frame
	else
		script.BuyButton:Clone().Parent = player:WaitForChild("PlayerGui"):WaitForChild("MainGui").Background.Shop.Frame
		
	end
end)


game.ReplicatedStorage.GuiPurchasedEXCLUSIVE.OnServerEvent:Connect(function(player)
	script.ShopExclusive:Clone().Parent = player:WaitForChild("PlayerGui"):WaitForChild("MainGui").Background
	script.ExclusiveButton:Clone().Parent = player:WaitForChild("PlayerGui"):WaitForChild("MainGui").Background.Shop.Frame
end)