Button not detecting clicks

Hello, could someone help me fix my script? It is supposed to enable another GUI, but the button is not sensing the clicks at all (not printing anything). There are also no errors in the output, and no GUIs (enabled or not) are covering it. All other buttons are also working.

Script:

local player = game.Players.LocalPlayer
local playergui = player.PlayerGui
local button = playergui.ScreenGui.IndexOpener
local gui = player.PlayerGui.IndexGUI

button.MouseButton1Click:Connect(function()
	print("Clicked!")
	print(tostring(gui.Enabled))
	gui.Enabled = not gui.Enabled
end)

Button:

GUI hierarchy:

image

Thanks for reading this post! (btw sorry if this is a dum issue)

Is there anything printing in the developer console? Are you sure itā€™s detecting the button properly?

Nothing is printing at all for some reason

i would say try putting WaitForChild but you said thereā€™s no errors (no index errors)

-- Put scripts that deal with multiple ScreenGui's in StarterPlayerScripts
local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")

local IndexGui = PlayerGui:WaitForChild("IndexGui") -- Keep names consistant
local ScreenGui = PlayerGui:WaitForChild("ScreenGui")
local IndexOpener = ScreenGui:WaitForChild("IndexOpener")

IndexOpener.MouseButton1Click:Connect(function()
  print("Clicked!")
  print(IndexGui.Enabled)
  IndexGui.Enabled = not IndexGui.Enabled
end)

I donā€™t think ā€œindexguiā€ exists (ā€œinfinite yield possibleā€), but I am able to use it as a variable??

it doesnā€™t exist because i didnā€™t write it as your original name

image

Try placing a script inside the ScreenGui where it detects once the button is clicked then fires a remote event within the other gui and then have a script that toggles the gui once said remote event is fired.

you donā€™t need a remote event for this

Tysm! (it got fixed now, was it just not loading in?)

1 Like

you probably just didnā€™t see the index error (Attempt to index ā€˜objectā€™ with nil)

so yeah it wasnā€™t loaded when the script started

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.