GUI stays even when destroyed

My script is:
local uis = game:GetService(“UserInputService”)
local isenabled = false

    uis.InputBegan:Connect(function(key)
    	if key.KeyCode == Enum.KeyCode.K then
               game.StarterGui.warn:Destroy()
    		end
    end)

I put it in StarterCharacterScripts and when I test it it does destroy the GUI but it still stays on the screen, its not visible in the explorer but its still on the screen. I tried doing warn.Enabled = false but that didnt work, then i tried transparency. I tried doing the same thing on a different GUI but the same thing happens. There is nothing in the console.

StarterGui is just a place holder for GUIs and the GUI each player see’s is stored inside their own PlayerGui folder which is inside of their Player instance inside of Players.

1 Like

so I would have to do game.players.localplayer and then the gui? yep okay that works

Well once you get the LocalPlayer you have then navigate to their PlayerGui folder.

Let me help you further since Zylter hasnt explained it thoroughly

Basically when you put something in StarterGui it gets parented to the PlayerGui inside of all the players’ PlayerGuis
So when getting a UI, you should always refrence the PlayerGui like so

local UI = plr.PlayerGui:WaitForChild("Example")

Don’t forget to add the waitforchild so it doesnt end up nil

So your edited code should look like this

uis.InputBegan:Connect(function(key)
    	if key.KeyCode == Enum.KeyCode.K then
         plr.PlayerGui:WaitForChild("warn"):Destroy()
     end
 end)