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 7 years ago
Edited 7 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.

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

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 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.

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")
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 — 7y
0
If you'd click the Accept Answer button down below, That'd be greatly appericiated. :) RubenKan 3615 — 7y
Ad
Log in to vote
0
Answered by 7 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.

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')
0
Also add WaitForChild('') after every line supercoolboy8804 114 — 7y

Answer this question