Shop GUI does not close when close button is clicked

Hello!

I am currently in the works of making a shop GUI, however, if you press the X button to close it, the script should be closing it, but it instead stays open and does not give any error message at all why it does not close the GUI. I have tried changing the script in different ways to close it, but it refuses to actually work. Here is the script:

closeButton = script.Parent

script.Parent.ClickDetector.MouseClick:Connect(function()
	script.Parent.Parent.Visible = false
end)

If you can then please help out!

1 Like

Can you please take a screenshot of the UI in explorer, so we can see how you have it structured?

It seems like the clickdetector is a descendant of a GuiObject? They only work on 3D objects like parts. For GuiButtons (TextButton, ImageButton), use MouseButton1Click.

closeButton = script.Parent

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Visible = false
end)

image

That was my original script, which did not work.

I think it should be a LocalScript instead.

try this and make sure you use localscript

closeButton = script.Parent
local plr = game.Player.LocalPlayer

script.Parent.ClickDetector.MouseClick:Connect(function()
        plr.PlayerGui.Shop.Shop.Visible = false
end)
1 Like

This worked, thanks a lot for helping to both of you! :smiley:

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