I have a local script that is inside a button that would activate a function. How it works is that when I click a button, It carries the object into a function in from a ModuleScript ReplicatedStorage.

This script activates it

local Player = game.Players.LocalPlayer
local ReplicatedStorage = game.ReplicatedStorage
local PlayerGui = Player.PlayerGui
local GuiFunctions = require(ReplicatedStorage.Gui.GuiFunctions)

local Button = script.Parent

Button.MouseButton1Click:Connect(function()--if it has been clicked
	--print(MainFrameChild,"has been set so if you click it, it opens it's page from mainframe")
	GuiFunctions.OpenPageFromMainFrame(Button)
end)

The function makes it so it if you press a button, the Main Menu(MainFrame) becomes invisible and if there is a Frame called [Button Name]Frame then it will open that. If it has a value called PurchasingPage inside the frame it will show another frame but it will first turn. Problem is that it gets stuck in an infinite WaitForChild loop trying to find it. I am testing to see it works until you reset. Once you reset, the game is unable to find it for some reason.

function GuiFunctions.OpenPageFromMainFrame(Button)--Open a new page from a button on the main menu of a Gui
	--Button = the pressed button
	
	local MainFrame = Button.Parent--Main Menu Frame
	local FullGui = MainFrame.Parent--Full Menu
	
	MainFrame.Visible = false--Turns the Main Menu Frame off
	
	local FrameOfButton = FullGui:FindFirstChild(Button.Name.."Frame")--Looks for any Frames to do with the Button pressed. By searching for the button name + "Frame"
	
	FullGui.Back.Visible = true--Makes it so players can undo and go back to the main menu if they please
	
	if FrameOfButton then--If there is a frame called [Button]Frame
		FullGui[Button.Name.."Frame"].Visible = true--That frame will be visible
		
		local FrameHasPurchasingPage = FrameOfButton:FindFirstChild("PurchasingPage")
		
		--PROBLEM
		if FrameHasPurchasingPage then--If it has the PurchasingPage value
			
			
			TreasureChestPurchase:WaitForChild("Title").Text = "" --Infinite wait
			TreasureChestPurchase:WaitForChild("PriceNumber").Text = ""
			TreasureChestPurchase:WaitForChild("Picture").Image = ""
			TreasureChestPurchase:WaitForChild("BuyButton").Visible = false
			
			TreasureChestPurchase.Visible = true--Makes TCP frame visible
		end
	end
end

Anyone able to help?