:WaitForChild not working

Hey developers,

I have gamepass script in Serverscriptservice that basically just parents a button to a gui, the gui does is parented to a Replicated storage folder.

Another script will parent the gui from the Replicated storage folder to the Playergui but, the problem is that when the gui is parented to Playergui the button won’t be parented to the gui.

Here is the script (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)

Help is appreciated!

Does it necessarily need a WaitForChild? Furthermore, I believe the issue lies on the fact that there is no way to keep track of the replicated items. You should try to give the clones different variables to parent it easier.

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