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

How come when I press z this function will not delete a gui?

Asked by 8 years ago

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))
0
Why have you put this in a pcall? User#5423 17 — 8y
0
Because I when I press Z I want to destroy the gui Capemanner 55 — 8y
0
You dont need a pcall for that User#5423 17 — 8y
0
What do you mean? Capemanner 55 — 8y
View all comments (3 more)
0
remove the pcall User#5423 17 — 8y
0
Still doesn't work? Capemanner 55 — 8y
0
Remove the pcall. Is this a Server Script, if so it will not take UserInput. M39a9am3R 3210 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

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.

0
Yes someone told me not use pcall.. Its saying it has a issue with the " end)) "? Capemanner 55 — 8y
0
The pcall would cause the script to not work. Just remove the 'pcall(' at the start and then the ')' at the end. IDidMakeThat 1135 — 8y
0
Still nothing I removed the "pcall(" and the " ) " and the script still doesn't work. Also thanks with your patience Capemanner 55 — 8y
0
I guess its not recognizing Im pressing Z? The local script is located in a spawnlocation if that could be a issue? Capemanner 55 — 8y
View all comments (3 more)
0
Give him the whole edited code :P User#11440 120 — 8y
0
You should put the local script in the StarterPlayerScripts IDidMakeThat 1135 — 8y
0
OH GOD IT WORKED I put the script in StarterPlayerScripts. Thank you so much :) Have a great day Capemanner 55 — 8y
Ad

Answer this question