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

How do I make a keybind GUI script OnPressed?

Hi all, I've recently made a script for a keybind Gui appearance. For some reason some times when I PlayTest it doesnt do anything.

  • Like 50% of the time it doesn't work when I press M right after I PlayTest.

The script is in a local script, I dont know if this is crucial information.

local Travel = script.Parent.Parent.Travel

p = game.Players.LocalPlayer
mouse = p:GetMouse()
local CanPress = true

mouse.KeyDown:connect(function(key)
	if not CanPress then
		return
	end
	CanPress = false
	if key == "m" then
		if Travel.Visible == true then
			Travel:TweenPosition(
				UDim2.new(-0.25, 0, 0.92, 0), --End Position
				"Out", -- Easing Direction
				"Quint", --Easing Style
				2, --How Long Does It Take?
				false --Other Tween Override
				)
				wait(2)
				Travel.Visible = false
		elseif Travel.Visible == false then
			Travel.Visible = true
			Travel:TweenPosition(
				UDim2.new(0.01, 0, 0.92, 0),
				"Out",
				"Quint",
				2,
				false
				)
		end
	CanPress = true
	end
end)

Also I've been trying for SO LONG for it to accept my question!!

1 comment

1

mouse.KeyDown is deprecated. Use UserInputService instead.

1 answer

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input,process)
	if process then return end--process is if any roblox processes happens like chatting, pressing esc etc
	if input.KeyCode == Enum.KeyCode.M then
		
	end
end)

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