Close gui script not working

I have a store gui in my game, but the close script does not work. If anyone could help, that would be great.

Here is my script:
script.Parent.MouseButton1Down:Connect(function()

script.Parent.Parent.Frame.Visible = false

end)

It is for a shop gui for a game in my group Classics Remake.

1 Like

If this is on a Server Script, the changes will not be replicated across to your side since it’s changing from the server’s POV

Change it to a LocalScript instead & if for some reason that doesn’t work, try this:

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local GuiToActivate = PlayerGui:WaitForChild("GuiThingy")

GuiToActivate.TextButton.MouseButton1Down:Connect(function()
    GuiToActivate.Frame.Visible = false
end)
2 Likes

First of all, can you check if your button is active? It would be script.Parent.Active. I would then check your explorer hierarchy and see if anything is not right there.

I’d also add a print to the function to see if it’s even firing the event.

I will try it, thanks for the help.

They did not work, any other suggestions?

Can you add print statements to check what runs and what doesn’t? You should have the GuiThingy named to what your GuiObject is

So, since the screen gui is called shop, thats what I replace GuiThingy with? Is that what you mean?

Yeah, that’s what you should have

Should look something like this:

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local GuiToActivate = PlayerGui:WaitForChild("Shop")
print("Script running")

GuiToActivate.TextButton.MouseButton1Down:Connect(function()
    print("Fired")
    GuiToActivate.Frame.Visible = false
end)

Also make sure to parent your TextButton & Frame correctly

Okay, I will try that and see.

This is how I have it all set up, is this right, becase their is a chance that it could be the problem.

The open button works, but the close button still does not.

B r u h

Okay, you have a lot of TextButtons, which the script can’t be able to identify which specific one you’re looking for

Fixed script:

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local GuiToActivate = PlayerGui:WaitForChild("Shop")
print("Script running")

GuiToActivate.Frame.Close.MouseButton1Down:Connect(function()
    print("Fired")
    GuiToActivate.Frame.Visible = false
end)

It worked, thank you so much for your help.

1 Like