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

Gui opening and closing?

Asked by 8 years ago
Edited 8 years ago

When i am in roblox studios just testing it, it works. But in the actual game it does not. I have tried multiple ways of fixing it but failed to figure it out. Here is my code.

01ButtonGuiScript = script.Parent.ButtonGuiScript
02Frame = script.Parent
03GUI = script.Parent.Parent
04MainMenuButton = Frame.MainMenuButton
05MainMenuFrame = script.Parent.Parent:FindFirstChild('MainMenuFrame')
06StartScreenbutton = Frame.StartScreenButton
07StartScreenFrame = script.Parent.Parent:FindFirstChild('StartScreenFrame')
08Inventorybutton = Frame.InventoryButton
09InventoryFrame = script.Parent.Parent:FindFirstChild('InventoryFrame')
10 
11 
12function MainMenubuttonClicked()
13    wait(0.1)
14    script.Parent.Parent:FindFirstChild('MainMenuFrame').Visible = true
15end
View all 29 lines...

I am getting the following errors inside roblox

  • MainMenuButton is not a valid member of frame. stack begin script 'Players.jo3thebomb.PlayerGui.MainScreenGui.ButtonScreenFrame.ButtonGuiScript'. stack end

-InventoryCloseButton is not a valid member of frame. stack begin script 'Players.jo3thebomb.PlayerGui.MainScreenGui.InventoryFrame.InventoryGuiScript'. - stack end

-ShopButton is not a valid member of frame. stack begin script 'Players.jo3thebomb.PlayerGui.MainScreenGui.MainMenuFrame.MainMenuScript'. - stack end

2 answers

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
8 years ago

Add :WaitForChild() on everything, this will make the script wait until the child is found. Your error comes because in studio everything is loaded instantly, in online mode, it has to be downloaded.

I also suggest using local variables, as these are more efficient.

1local ButtonGuiScript = script.Parent:WaitForChild("ButtonGuiScript")
2local Frame = script.Parent
3local GUI = script.Parent.Parent
4local MainMenuButton = Frame:WaitForChild("MainMenuButton")
5local MainMenuFrame = script.Parent.Parent:WaitForChild("MainMenuFrame")
6local StartScreenbutton = Frame:WaitForChild("StartScreenButton")
7local StartScreenFrame = script.Parent.Parent:WaitForChild("StartScreenFrame")
8local Inventorybutton = Frame:WaitForChild("InventoryButton")
9local InventoryFrame = script.Parent.Parent:WaitForChild("InventoryFrame")
0
It worked! Thank you so much! If there are any tutorials or anything i could get from you, Links anything. Pass me them! :) jo3thebomb 12 — 8y
0
If you'd click the Accept Answer button down below, That'd be greatly appericiated. :) RubenKan 3615 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

What you didn't do was add locals. Locals are what substitutes something for something else, and this is one core thing you left out.

1local ButtonGuiScript = script.Parent.ButtonGuiScript
2local Frame = script.Parent
3local GUI = script.Parent.Parent
4local MainMenuButton = Frame.MainMenuButton
5local MainMenuFrame = script.Parent.Parent:FindFirstChild('MainMenuFrame')
6local StartScreenbutton = Frame.StartScreenButton
7local StartScreenFrame = script.Parent.Parent:FindFirstChild('StartScreenFrame')
8local Inventorybutton = Frame.InventoryButton
9local InventoryFrame = script.Parent.Parent:FindFirstChild('InventoryFrame')
0
Also add WaitForChild('') after every line supercoolboy8804 114 — 8y

Answer this question