Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I need help to delete a Gui after I press a certain Button?

Asked by 8 years ago
Edited 8 years ago

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))

1 answer

Log in to vote
0
Answered by 8 years ago

To delete it, call Destroy on the one inside the PlayerGui, like this:

local Gui = game.Players.LocalPlayer.PlayerGui:FindFirstChild(YourGuiName)
if Gui then Gui:Destroy() end

Replacing 'YourGuiName' with the name of the GUI.

Also, your UserInputService stuff needs to be in a local script, while the Touched stuff should probably be in a normal script.

0
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. Capemanner 55 — 8y
0
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. IDidMakeThat 1135 — 8y
0
Ok one more thing what do you mean by call destroy on the insidie of PlayerGui. Where would that exactly be? Capemanner 55 — 8y
0
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. IDidMakeThat 1135 — 8y
0
I put the Destroy function in in the pcall and its not working? Capemanner 55 — 8y
Ad

Answer this question