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

Gui opening and closing?

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.

ButtonGuiScript = script.Parent.ButtonGuiScript
Frame = script.Parent
GUI = script.Parent.Parent
MainMenuButton = Frame.MainMenuButton
MainMenuFrame = script.Parent.Parent:FindFirstChild('MainMenuFrame')
StartScreenbutton = Frame.StartScreenButton
StartScreenFrame = script.Parent.Parent:FindFirstChild('StartScreenFrame')
Inventorybutton = Frame.InventoryButton
InventoryFrame = script.Parent.Parent:FindFirstChild('InventoryFrame')


function MainMenubuttonClicked()
	wait(0.1)
	script.Parent.Parent:FindFirstChild('MainMenuFrame').Visible = true
end

function StartScreenbuttonClicked()
	wait(0.1)
	script.Parent.Parent:FindFirstChild('StartScreenFrame').Visible = true
end

function InventorybuttonClicked()
	wait(0.1)
	script.Parent.Parent:FindFirstChild('InventoryFrame').Visible = true
end

Inventorybutton.MouseButton1Click:connect(InventorybuttonClicked)
MainMenuButton.MouseButton1Click:connect(MainMenubuttonClicked)
StartScreenbutton.MouseButton1Click:connect(StartScreenbuttonClicked)

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

✓ Accepted answer

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.

local ButtonGuiScript = script.Parent:WaitForChild("ButtonGuiScript")
local Frame = script.Parent
local GUI = script.Parent.Parent
local MainMenuButton = Frame:WaitForChild("MainMenuButton")
local MainMenuFrame = script.Parent.Parent:WaitForChild("MainMenuFrame")
local StartScreenbutton = Frame:WaitForChild("StartScreenButton")
local StartScreenFrame = script.Parent.Parent:WaitForChild("StartScreenFrame")
local Inventorybutton = Frame:WaitForChild("InventoryButton")
local InventoryFrame = script.Parent.Parent:WaitForChild("InventoryFrame")

2 comments

0

It worked! Thank you so much! If there are any tutorials or anything i could get from you, Links anything. Pass me them! :)

0

If you'd click the Accept Answer button down below, That'd be greatly appericiated. :)

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.

local ButtonGuiScript = script.Parent.ButtonGuiScript
local Frame = script.Parent
local GUI = script.Parent.Parent
local MainMenuButton = Frame.MainMenuButton
local MainMenuFrame = script.Parent.Parent:FindFirstChild('MainMenuFrame')
local StartScreenbutton = Frame.StartScreenButton
local StartScreenFrame = script.Parent.Parent:FindFirstChild('StartScreenFrame')
local Inventorybutton = Frame.InventoryButton
local InventoryFrame = script.Parent.Parent:FindFirstChild('InventoryFrame')

1 comment

0

Also add WaitForChild('') after every line

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