So I have a GUI that consists of a lot of frames within other frames, and I was having trouble because they stopped working and I was getting the error that the script thought certain frames didn't exist where I said they did, but I fixed some of it by using :WaitForChild(). The problem now, is that the same thing is happening for a lot of the other variables in my scripts (that are within the GUI buttons) and It would take a long time to put the :WaitForChild() in every variable (around 15 variables per script and around 50 scripts) My question is, is it possible to load all of the frames and children of the frames before the scripts run? I think that would solve it but I'm not sure how to do that. Any help is appreciated! Here's an example script

local BUTTON = script.Parent
local nframe = BUTTON.Parent.Parent:WaitForChild("NameFrame")
local name = nframe.Label.Text
local FRAME = BUTTON.Parent.Parent
local NBox1 = FRAME.ColumnFrame2.BoxFrame2
local NBox2 = FRAME.ColumnFrame2.BoxFrame3
local NBox3 = FRAME.ColumnFrame2.BoxFrame4
local NBox4 = FRAME.ColumnFrame2.BoxFrame5

local HBox1 = FRAME.ColumnFrame3.BoxFrame2
local HBox2 = FRAME.ColumnFrame3.BoxFrame3
local HBox3 = FRAME.ColumnFrame3.BoxFrame4
local HBox4 = FRAME.ColumnFrame3.BoxFrame5

local htext1 = HBox1.TextLabel
local ntext1 = NBox1.TextLabel
local htext2 = HBox2.TextLabel
local ntext2 = NBox2.TextLabel
local htext3 = HBox3.TextLabel
local ntext3 = NBox3.TextLabel
local htext4 = HBox4.TextLabel
local ntext4 = NBox4.TextLabel


function getPC()
	local player = game.Players.LocalPlayer
	local char = player.Character

	return player, char
end

function giveTool(name)
	local player, char = getPC()
	local backpack = player.Backpack
	local tools = game.Lighting.Tools

	local made = tools:FindFirstChild(name)

	if made ~= nil then print("toolnotnil")
		made:clone().Parent = backpack
	else print("toolisnil")
	end
end

function giveItem(name)
	local player, char = getPC()
	local pack = player.Pack
	local items = game.Lighting.Items

	local real = items:findFirstChild(name)

	if real ~= nil then
		local new = real:clone()
		new.Parent = pack
	else
	end
end
--------------------------------------------
function delete_items1()
		local player, char = getPC()
	local pack = player.Pack
	local itemname1 = FRAME.RowFrame2.TextLabel.Text
	local item1 = pack:FindFirstChild(itemname1)
	
	item1:remove()
		
end

function delete_items2()
		local player, char = getPC()
	local pack = player.Pack
	local itemname2 = FRAME.RowFrame3.TextLabel.Text
	local item2 = pack:FindFirstChild(itemname2)
	
	item2:remove()
		
end

function delete_items3()
		local player, char = getPC()
	local pack = player.Pack
	local itemname3 = FRAME.RowFrame4.TextLabel.Text
	local item3 = pack:FindFirstChild(itemname3)
	
	item3:remove()
		
end

function delete_items4()
		local player, char = getPC()
	local pack = player.Pack
	local itemname4 = FRAME.RowFrame5.TextLabel.Text
	local item4 = pack:FindFirstChild(itemname4)
	
	item4:remove()
		
end
-----------------------------------------------

function onMouseButton1Down(mouse)
	local player, char = getPC()
	local pack = player.Pack
	
	
	if htext1.TextColor3 == Color3.new(0,85,0)
		--and htext2.TextColor3 == Color3.new(0,85,0)
		--and htext3.TextColor3 == Color3.new(0,85,0)
		--and htext4.TextColor3 == Color3.new(0,85,0)
		then
		
		delete_items1()
		
		htext1.Text = htext1.Text - ntext1.Text
		--htext2.Text = htext2.Text - ntext2.Text
		--htext3.Text = htext3.Text - ntext3.Text
		--htext4.Text = htext4.Text - ntext4.Text
		
		
		
		
	giveItem(name)
	else
		BUTTON.Text = "Not Enough Resources"
		wait(4) BUTTON.Text = "Craft"
	end
	-----------------------------------------------------------------------------
	if htext1.Text < ntext1.Text then htext1.TextColor3 = Color3.new(255,0,0) end
	
	if htext2.Text ~= "" and htext2.Text < ntext2.Text then htext2.TextColor3 = Color3.new(255,0,0) end
	
	if htext3.Text ~= "" and htext3.Text < ntext3.Text then htext3.TextColor3 = Color3.new(255,0,0) end
	
	if htext4.Text ~= "" and htext4.Text < ntext4.Text then htext4.TextColor3 = Color3.new(255,0,0) end
	------------------------------------------------------------------------------
end
BUTTON.MouseButton1Down:connect(onMouseButton1Down)

2 comments

0

If you usually just add "wait(3)" to the start of the script, it should work.

0

You can't preload a GUI.