I have a button in my ScreenGui that when pressed is supposed to destroy the ScreenGui it is apart of. When I test this in a local server on Studio, when the button is pressed, the ScreenGui itself disappears, but the actual item in the PlayerGui is still there.
Why won't the ScreenGui be destroyed?
Here's the code:
script.Parent.MouseButton1Click:Connect(function() --script.Parent is the TextButton script.Parent.Parent:Destroy() --script.Parent.Parent is the Gui end)
This is due to the ResetOnSpawn
property of the ScreenGui
. Set it to false
and it should destroy when you ask it to.
Try this, this just gets it out of the localplayers GUI.
script.Parent.MouseButton1Click:Connect(function() --script.Parent is the TextButton local gui = game.Players.LocalPlayer.PlayerGui.GUINAME -- Change the name to your GUI's Name local dgui = gui:Destroy() end)