Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Why does this Gui LocalScript only work in studio?

Asked by 9 years ago

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

Log in to vote
0
Answered by 9 years ago

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

Ad

Answer this question