Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does this Gui LocalScript only work in studio?

This script needs to check the text of a textlabel, and make a certain GUI invisible based on that. The output I get when I run a sever is "Easy is not a valid member of Frame" But it is...

gui = game.Players.LocalPlayer.PlayerGui.ScreenGui
Step2 = gui.Step2
Hard = Step2.Hard
Easy = Step2.easy
step1choice = Step2.step1choice

Step2.Changed:connect(function()
	local value = Step2.Visible
if step1choice.Text == "Action & Adventure" then
	Hard.Visible = false
elseif step1choice.Text == "Building & Comedy" then
	Hard.Visible = false
elseif step1choice.Text == "Horror & Scifi" then
	Easy.Visible = false
elseif step1choice.Text == "Town & RPG" then 
	Hard.Visible = false	
end

end)

1 answer

✓ Accepted answer

What is most likely happening is the script is firing, before the GUI is loading.

To make sure something loads correctly use the WaitForChild method.

Example:

Easy = Step2:WaitForChild("easy")

What this will do is wait for easy to load before continuing.

The best thing to do is start with the top of the hierarcy which would be gui, like this:

gui = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui")

More on WaitForChild

This discussion is preserved as it was. New answers, comments, and votes are closed.