Keybind Animations

Hey,

I have an Airstairs vehicle which can raise and fall to adjust to the height of the aircraft.
I’m trying to put key binds onto it to make the users have easier control over it, it works as intended for the most part, however I’m trying to eradicate an issue where if you press both the raise and fall keybind (in my case ‘q’ & ‘e’) at the same time, or between KeyUp It will run them at the same time which messes up the animation.

Keybind Script (LocalScript)

mouse.KeyDown:connect(function(key)
	key = key:lower() 
	if key == 'q' and key ~= 'e' then
		DOWN:FireServer()
	end
end)

mouse.KeyUp:connect(function(key)
	key = key:lower() 
	if key == 'q' and key ~= 'e' then
		STOP:FireServer()
	end
end)

Function Script (ServerScript)


function setRampRaiseT()
	Hold = true
	
	while Hold do
		StepMotor.DesiredAngle += TurnRateA * RS.Heartbeat:Wait()
		BasketMotor.DesiredAngle -= TurnRateA * RS.heartbeat:Wait()
	end
	
end

function setRampLowerT()
	Hold = true
	while Hold do
		StepMotor.DesiredAngle += TurnRateB * RS.Heartbeat:Wait()
		BasketMotor.DesiredAngle -= TurnRateB * RS.heartbeat:Wait()
	end
end


Events.UP.OnServerEvent:Connect(setRampRaiseT) -- MOVE
Events.STOP.OnServerEvent:Connect(function() Hold = false end) -- STOP

I tried to use the ‘~=’ operator to see if that would fix it, but unfortunately I have not been blessed with that simple fix.

Any help would be appreciated

1 Like

You might be able to have two Boolean variables, one for moving up and another for moving down; and have them controlled by the remote events.
For example, this could be done as a loop:

while wait(0.1) do -- Could be shorter or longer, 0.1 is a placeholder
	if moveUp and not moveDown then
		-- Move up (Tween for smoothing?)
	elseif moveDown and not moveUp then
		-- Move down (Tween for smoothing?)
	end
end
1 Like