I have received help earlier but I'm not on with coding.. I'm basically making it If I press Z it'll delete a Gui I make appear in a different script. When I press Z in game nothing happens? Much appreciated if helped
pcall(game:GetService("UserInputService").InputBegan:connect(function(key) if key.KeyCode == Enum.KeyCode.Z then print 'the key Z has been pressed' local Gui = game.Players.LocalPlayer.PlayerGui:FindFirstChild(One) if Gui then Gui:Destroy() end else print 'Y u no press Z?' end end))
The problem is that in this:
local Gui = game.Players.LocalPlayer.PlayerGui:FindFirstChild(One)
One
refers to the variable named One
, whereas in this:
local Gui = game.Players.LocalPlayer.PlayerGui:FindFirstChild("One")
"One"
is a string literal. To fix this, replace One
in that line with "One"
(I probably should have mentioned this earlier)
Additionally, you do not need to (and should not) use pcall
in this code.