Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My Pause Menu On KeyDownEvent Not Working?

?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

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.

2 comments

0

Thank you for trying, but the error is still present however.

0

I've edited my answer. Also, have you tried fixing the typos?

This discussion is preserved as it was. New answers, comments, and votes are closed.