Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't the ScreenGui be destroyed?

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)

6 comments

0

try making the gui a variable, so local gui = script.Parent.Parent (make sure you check your output) then do gui:Destroy()

0

Already tried that.

1

is your script a local script? If not convert it

0

Server scripts can't make changes to the clients gui, only local scripts can

0

Yeah I'm sure its not a local script or else this should work. ^^

0

It's a local script.

2 answers

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)

1 comment

0

Completely unnecessary code. local dgui wouldnt work since the gui is destroyed it should be game.Players.LocalPlayer.PlayerGui.GUINAME:Destroy()

This discussion is preserved as it was. New answers, comments, and votes are closed.