I’m trying to make a helicopter and I need to make the throttle, yaw, and collective system. Problem is, these are ventures that require input based off of keys that are held down, rather than pressed once.
Here’s what I came up with, but the problem is, When I hold down the button, It’ll fire the remote event with the inputs like 5000 times and I only need it to do it once.
local UIS = game:GetService("UserInputService")
local remoteEvent = game.ReplicatedStorage.Relay
local canTrigger = true
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftShift then
remoteEvent:FireServer("LShift")
elseif input.KeyCode == Enum.KeyCode.LeftControl then
remoteEvent:FireServer("LCtrl")
end
if input.KeyCode == Enum.KeyCode.E then
remoteEvent:FireServer("EYaw")
elseif input.KeyCode == Enum.KeyCode.Q then
remoteEvent:FireServer("QYaw")
end
if input.KeyCode == Enum.KeyCode.LeftShift then
remoteEvent:FireServer("LShift")
elseif input.KeyCode == Enum.KeyCode.LeftControl then
remoteEvent:FireServer("LCtrl")
end
if input.KeyCode == Enum.KeyCode.O then
remoteEvent:FireServer("OCollective")
elseif input.KeyCode == Enum.KeyCode.K then
remoteEvent:FireServer("KCollective")
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
remoteEvent:FireServer("LShiftNil")
elseif input.KeyCode == Enum.KeyCode.LeftControl then
remoteEvent:FireServer("LCtrlNil")
end
if input.KeyCode == Enum.KeyCode.E then
remoteEvent:FireServer("EYawNil")
elseif input.KeyCode == Enum.KeyCode.Q then
remoteEvent:FireServer("QYawNil")
end
if input.KeyCode == Enum.KeyCode.O then
remoteEvent:FireServer("OCollectiveNil")
elseif input.KeyCode == Enum.KeyCode.K then
remoteEvent:FireServer("KCollectiveNil")
end
end)
If someone could help, I’d really appreciate it.
Thanks,
– Luke