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

My Pause Menu On KeyDownEvent Not Working?

Asked by 9 years ago

?Hi and thank you for looking at my question, I made a pause menu which where it'll open if you press down a certain key, but it isn't working. Not one bit, here's the code of Lua that I made for this.

repeat wait() until game.Players.LocalPlayer

local p = game.Players.LocalPlayer

local m = p.GetMouse ()

local folder = p.PlayerGui:WaitForChild("Pause Gui")

local guitoopen = folder ["StarterGui"]



m.KeyDown:conect(function(key)

if key: lower() == "p"then

if guitoopen.Visible then

guitoopen.Visble = false

else

guitoopen.Visible = true

end

end

end)

I have no idea why it is acting this way. So If you can help me, that'll be great!

1 answer

Log in to vote
1
Answered by 9 years ago

The issue here is that you have a few typos. However, you shouldn't use KeyDown in the first place because it's deprecated. Use UserInputService instead.

game:GetService("UserInputService").InputBegan:connect(function(key) --Triggered on an input
    if key.KeyCode == Enum.KeyCode.P then --If the input is P then
        if guitoopen.Visible then
            guitoopen.Visible = false
        else
            guitoopen.Visible = true
        end
    end
end)

EDIT: I believe there's a problem with how you defined guitoopen. If folder is the Pause GUI, how can guitoopen be folder["StarterGui"]? That would require the Pause GUI to be the StarterGui parent, which is not possible.

0
Thank you for trying, but the error is still present however. GreekGodOfMLG 244 — 9y
0
I've edited my answer. Also, have you tried fixing the typos? IcyArticunoX 355 — 9y
Ad

Answer this question