Help with a open gui script

Title. I have 2 scripts that open a gui. One by pressing G on your keyboard, and by pressing a button. For some weird reason, only the G method works to open the gui.

No errors come out in output. Help.
G script:

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui") 

local shopGui = playerGui:WaitForChild("ShopGui")
local imageButton = shopGui:WaitForChild("ImageButton")
local scrollingFrame = shopGui:WaitForChild("Background")


local function toggleVisibility()
	scrollingFrame.Visible = not scrollingFrame.Visible
end


imageButton.Activated:Connect(toggleVisibility)

UserInputService.InputBegan:Connect(function(input, processed)
	
	if not processed and input.KeyCode == Enum.KeyCode.G then
		toggleVisibility()
	end
end)

Button script:

local scrollingframe = script.Parent.Parent. Background

script.Parent.Activated:Connect(function()

scrollingframe.Visible = not scrollingframe.Visible

end)

The g script is located in StarterPlayerScripts
The image script is located in:


Please help

1 Like

To detect if a GUIButton has been clicked, you should use the .MouseButton1Click event.

1 Like

still didn’t work, the button script worked just fine before the G script.

The main problem is probably the fact that the button itself is trying to make the Scrolling Frame Visible while the main script is doing the same, so you basically have two scripts countering each other resulting in nothing showing up. My solution would be to delete the Button script entirely.

1 Like

Activated works the same but better and more universally so that’ s not the issue.

welp i want to do both. Surely that’s possible? Should I do the C-Frame method?

No im saying, in the G script it looks like you’re already calling the button when it is clicked. Which is fine you can leave that, but the open script in the Button doing the same thing. So if you delete the open script in the button you should be good. Or you could just delete

in the G script

I understand that both of them will not work, but surely there is way at least, to make them both work.

Both the “G” press and the “Image button” will work.

Try deleting this line and testing it please

I believe this is the problem

1 Like

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