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
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
You could use UserInputService:BindAction() to let all game platforms (Computer, Xbox, Mobile) interact with a keybind. It might also help your input problem.
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.