How in the world do I do keybinds?

db = false
door = false
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if not gameProcessedEvent then
	if input.KeyCode == Enum.KeyCode.Q then
		if not db then 
			db = true
			if not door then door = true
				script.Parent.Door.Sound:play()
				for i=0,15 do
					script.Parent.Door.CFrame = script.Parent.Door.CFrame - Vector3.new(0,0.8,0)
					wait()
				end
				script.Parent.Door.CFrame = script.Parent.Door.CFrame - Vector3.new(0,0.2,0)
				db = false
			elseif door then door = false
				script.Parent.Door.Sound:play()
				for i=0,15 do
					script.Parent.Door.CFrame = script.Parent.Door.CFrame + Vector3.new(0,0.8,0)
					wait()
				end
				script.Parent.Door.CFrame = script.Parent.Door.CFrame + Vector3.new(0,0.2,0)
			end
			db = false
		end
	end
end

end)

1 Like

I changed it to Q to see if anything would happen then.

Try removing the gameProcessedEvent if statement. I’ve had some issues with it before.

1 Like

That didn’t do anything. Any other ideas?

I don’t see the print in there. Did you remove it? Try adding it back, right after the keycode check.

If this is any help, this is the script for the mouse click that I’m basing the keybind script off. This script works perfectly fine.

db = false
door = false
local UserInt = game:GetService("UserInputService")

script.Parent.DoorButton.ClickDetector.MouseClick:connect(function()
if not db then 
	db = true
	if not door then door = true
		script.Parent.Door.Sound:play()
		for i=0,15 do
			script.Parent.Door.CFrame = script.Parent.Door.CFrame - Vector3.new(0,0.8,0)
			wait()
		end
		script.Parent.Door.CFrame = script.Parent.Door.CFrame - Vector3.new(0,0.2,0)
		db = false
	elseif door then door = false
		script.Parent.Door.Sound:play()
		for i=0,15 do
			script.Parent.Door.CFrame = script.Parent.Door.CFrame + Vector3.new(0,0.8,0)
			wait()
		end
		script.Parent.Door.CFrame = script.Parent.Door.CFrame + Vector3.new(0,0.2,0)
	end
	db = false
end

end)

1 Like

Nothing printed. I made sure that it would show up in the output but nothing.

Do you have a print in there? I didn’t see one, unless you added it back.

I added it back, right where you said to.

You could use UserInputService:BindAction() to let all game platforms (Computer, Xbox, Mobile) interact with a keybind. It might also help your input problem.

Here’s the dev article link for this: ContextActionService | Documentation - Roblox Creator Hub

I don’t understand the article. It’s ok, I think I’ll stick with clicking since no one I’ve talked to yet can find a solution. Thanks for the help.

1 Like

I can test the script tomorrow and I’ll give you the working one. Glad I could help. (sorta)

A major problem with your code is that it’s all ran on a localscript. Actually, moving parts this way would only show up for you and no one else (you can try it in studio with multiple players). I suggest making a server-sided script for the door moving.

2 Likes

I just figured out the problem. I forgot that LocalScripts won’t run in Workspace lol. Try placing it in StarterPlayerScripts and try again.

Edit: You will need to change your reference to the door