Hello,
I am scripting a system where if a button is clicked, a frame appears. The button that triggers this is in another ScreenGui than the ScreenGui that the frame is in.
For some reason, the script is not detecting the toggle button. Any ideas why this is?
local Toggle = game.StarterGui:FindFirstChild("GameGui").MainFrame.ButtonFrame.HouseButton_Frame:FindFirstChild("ImageButton")
local mainFrame = script.Parent
Toggle.MouseButton1Click:Connect(function()
mainFrame.Visible = true
end)
I know the issue. Nothing in StarterGui is shown on screen. It is stored in PlayerGui. Hooking events to objects in StarterGui does absolutely nothing. Just change “Toggle” to this
local Toggle = game.Players.LocalPlayer.PlayerGui:FindFirstChild("GameGui").MainFrame.ButtonFrame.HouseButton_Frame:FindFirstChild("ImageButton")
game.StarterGui is not where your gui is located! you can either do it relative to your scripts location, or do game.Players.LocalPlayer.PlayerGui! Your scripts move to a location under your player object called “PlayerGui” so if you want something like a gui to appear on the clients screen, you’ll have to refer to that!
local mainFrame = script.Parent
local Button = mainFrame.ButtonFrame.HouseButton_Frame.ImageButton
Button.MouseButton1Click:Connect(function()
mainFrame.Visible = not mainFrame.Visible
end)
You don’t have to reference GuiObject’s from inside the PlayerGui folder, you can instead reference them correctly from as they appear in the StarterGui folder by referencing the various parents/children of GuiObject instances.