How to delete a GUI using a button

How do I make it so that when a button is clicked. It destroys the GUI/Parent.

You can use :Destroy() on the gui when a button is clicked

1 Like
local button = --define

button.Activated:Connect(function()
       button.Parent:Destroy()
end)

Will this work?

script.Parent.MouseButton1Click:Connect(function()
	print("Destroying Menu!")
	wait(1)
	game.StarterGui.StarMenuMain:Destroy()
	game.StarterGui.StarMenuMessage:Destroy()
end)
1 Like

When a player joins, everything in the StarterGui is cloned into their PlayerGui. You want to use the PlayerGui not StarterGui. Try this:

local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	print("Destroying Menu!")
	wait(1)
	player.PlayerGui.StarMenuMain:Destroy()
	player.PlayerGui.StarMenuMessage:Destroy()
end)
3 Likes

you either destroy it or make visible to false so you can just toggle it back and forth

I’m making it destroy because it is op and I don’t want exploiters using it.