So you got this problem saying it couldn't find the object you wanted it to find, well no fear this will help you try to fix it and teach my you why that error happens!

Why it happens?
The bug happens because it hasn't loaded the assets in so when the script runs it, It will just say not valid then after it loads.
This is common with summoning assets to the game or moving assets around and other scripts need to access it.

How to fix the problem in a gui
To fix the problem is somewhat easy.

1st one:
Let's say you're summoning a frame onto the player's gui here is what you would normally do
Script 1 : Making the frame
script.Parent.MouseButton1Click:connect(function()
local frame = Instance.new("Frame")
frame.Parent = script.Parent.Parent
end)

Script 2 : changing it
script.Parent.MouseButton1Click:connect(function()
for i,v in pairs(script.Parent.Parent.Parent:GetChildren()) do
if v:IsA("Frame") thenv.Name = 'Access granted'
end
end)

Output: (Also I'm saying this happens)
Could not find 'Frame' a nil value or something like it

To fix it go to the script 2 and change it to:
script.Parent.MouseButton1Click:connect(function()
for i,v in pairs(script.Parent.Parent.Parent:GetChildren()) do
v:WaitForChild()
if v:IsA("Frame") thenv.Name = 'Access granted'
end
end)

We added v:WaitForChild() because this time for the script to pass through it needs to wait for the child aka the frame to be found.

Workspace errors
Let's say you have a script summoning parts and another script will change it's color.
Script 1: Summon Parts
while true do wait(1)
local part = Instance.new("Part")
part.Parent = workspace
end

Script 2: changing color
while wait(0.01) do
for i,v in pairs(game.Workspace:GetChildren()) do
if v:IsA("Part") then
v.BrickColor = BrickColor.new("Really Red")
end
end
end

Let's say this error appears:
Could not find 'Part' nil value

To fix it like the screen gui one
add between for i,v in pairs(game.Workspace:GetChildren()) do and if v:IsA("Part") then
v:WaitForChild()
As the same it will allow the script to run if 'Part' is a valid member of workspace.