You press G and this GUI comes up. I want it so when you press it again the GUI will disappear. Instead it just makes another one come up and you can virtually make an infinite amount of these GUI's appear. Any way to fix this here? Here's the code:
local guis = game.ReplicatedStorage.GUIs
local player = script.Parent.Parent
local phoneactive = script.Parent:FindFirstChild("Phone")
function onKeyPress(inputObject, gameProccessedEvent)
if not gameProccessedEvent then -- If not using an event, run this code
if inputObject.KeyCode == Enum.KeyCode.G then
if phoneactive then
script.Parent.Phone:Destroy()
else
local help = guis.Phone:Clone()
help.Parent = player.PlayerGui
player.PlayerGui.PlayerAudio.Pullup:Play()
end
end
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
Any help is appreciated :)

1 comment
maybe if you make a local variable called help = nil at line 4 then at line 9 help:Destroy() and at line 11 instead of local help make it say help.