I'm Making a Pokémon RPG and I'd like to delete my gui I created after I pressed a certain Button. Much Appreciated if helped :) I was trying earlier to do : game.Lighting.One:Remove() But it only would kill the file location it wouldn't kill the gui on the screen
--onTouch Gui Shall Appear
local Gui = game.Lighting.One -
function GiveGui(Player)
if Player.PlayerGui:FindFirstChild(Gui.Name)~=nil then return end
Gui:Clone().Parent=Player.PlayerGui
end
script.Parent.Touched:connect(function(hit)
local Player=game.Players:GetPlayerFromCharacter(hit.Parent)
if Player==nil then return end
GiveGui(Player)
end)
--if _ Keydown delete and create new Gui
pcall(game:GetService("UserInputService").InputBegan:connect(function(key)
if key.KeyCode == Enum.KeyCode.A then
print 'the key A has been pressed'
--THIS IS WHERE I WOULD DELETE MY GUI
else
print 'Y u no press A?'
end
end))

5 comments
I seperated the UserInputService into a local script. But for the Destroy Function can you be a bit more clear about that. Im not one with scripting.
The Destroy() function is used like Remove(), and is prefered for deleting objects. You need to find the copy of the GUI inside the PlayerGui, then destroy it.
Ok one more thing what do you mean by call destroy on the insidie of PlayerGui. Where would that exactly be?
You are putting the GUI inside of PlayerGui. Therefore, you need to Destroy() the GUI there too. The sample I have provided should work if you replace YourGuiName with the name of the GUI.
I put the Destroy function in in the pcall and its not working?