When changing multiple inputs how do I keep just the held keys working?

I have a crane and the controls work fine with UserInputService, but say I’m holding 3 keys down (w, d, & f) sometimes the order I press the keys makes it so I don’t get the input of all 3 keys.

Also when I release just one of the keys or while the keys are held I click my right mouse button to move the camera everything stops moving. I’d like to have it so if I’m moving the crane controls by pressing w, d and f and I release w, I want d and f to continue working.

I know I have everything in the InputEnded section set to stop when any InputEnded fires, but it’s the closest I’ve come to getting it to work the way I want. I’ve tried various ways of setting each key released input to make only that input value zero out by setting that specific control to its ‘CurrentAngle’, ‘CurrentPosition’, or 0 with no success.

This script (or section of it anyway) is in a LocalScript in the StarterCharacterScripts.
The Player is also sitting on a VehicleSeat so I don’t know if that’s causing some issues as well.

-- stuff above is naming variables & checking if humanoid is on the vehicleseat.

UIS.InputBegan:connect(function(InputObject,gameProcessedEvent)
	if jib then -- make sure to only do anything if they're sitting down
		if UIS:IsKeyDown(Enum.KeyCode.W) then
			--print"Trolley out"
			--working = Enum.KeyCode.W
			trolley.TargetPosition = 251
		end
		if UIS:IsKeyDown(Enum.KeyCode.S) then
			--print"Trolley in"
			--working = Enum.KeyCode.S
			trolley.TargetPosition = 0
		end
		if UIS:IsKeyDown(Enum.KeyCode.A) then
			--print"Jib left"
			--working = Enum.KeyCode.A
			jib.AngularVelocity = .05
		end
		if UIS:IsKeyDown(Enum.KeyCode.D) then
			--print"Jib right"
			--working = Enum.KeyCode.D
			jib.AngularVelocity = -.05
		end
		if UIS:IsKeyDown(Enum.KeyCode.R) then
			--print"Bucket up"
			--working = Enum.KeyCode.R
			hoist.TargetPosition = 0
		end
		if UIS:IsKeyDown(Enum.KeyCode.F) then
			--print"Bucket down"
			--working = Enum.KeyCode.F
			hoist.TargetPosition = -150
		end
		if UIS:IsKeyDown(Enum.KeyCode.Q) then
			--print"Bucket opening"
			--working = Enum.KeyCode.Q
			inner.DesiredAngle = math.rad(-60)
			outer.DesiredAngle = math.rad(-60)
		end
		if UIS:IsKeyDown(Enum.KeyCode.E) then
			--print"Bucket closing"
			--working = Enum.KeyCode.E
			inner.DesiredAngle = 0
			outer.DesiredAngle = 0
		end
		if UIS:IsKeyDown(Enum.KeyCode.L) then
			if not debounce then
				debounce = true
				--print"Crane lights"
				if l5.Enabled == true then
					l1.Material = "Slate"
					l2.Enabled = false
					l3.Enabled = false
					l4.Enabled = false
					l5.Enabled = false
				else 
					l1.Material = "Neon"
					l2.Enabled = true
					l3.Enabled = true
					l4.Enabled = true
					l5.Enabled = true
				end
				wait(.4)
				debounce = false
			end
		end
	end
end)		

UIS.InputEnded:connect(function(InputObject,gameProcessedEvent)
		jib.AngularVelocity = 0
		trolley.TargetPosition = trolley.CurrentPosition
		hoist.TargetPosition = hoist.CurrentPosition
		inner.DesiredAngle = inner.CurrentAngle
		outer.DesiredAngle = outer.CurrentAngle
		--print("InputEnded") 
end)
1 Like

Couldn’t you just make the function connected to the “.InputEnded” event perform the reverse of what the function connected to the “.InputStarted” event does?

I tried using if not IsKeyDown since I couldn’t find anything about it.
I just read up on how to use if not IsKeyDown in the InputBegan section with else so I’m going to give that a try tonight.

So if I do it this way then for example if I hold W, D & F the crane performs those movements correctly.
When I release just one of the keys (say W) then it stops moving completely even though I still hold the D & F keys down, but if I then release just the D key (still holding F) and press it again then the D & F movements work again.

UIS.InputBegan:connect(function(InputObject,gameProcessedEvent)
	if jib then -- make sure to only do anything if they're sitting down
		if UIS:IsKeyDown(Enum.KeyCode.W) then
			--print"Trolley out"
			trolley.TargetPosition = 251
		end
		if UIS:IsKeyDown(Enum.KeyCode.S) then
			--print"Trolley in"
			trolley.TargetPosition = 0
		end
		if UIS:IsKeyDown(Enum.KeyCode.A) then
			--print"Jib left"
			jib.AngularVelocity = .05
		end
		if UIS:IsKeyDown(Enum.KeyCode.D) then
			--print"Jib right"
			jib.AngularVelocity = -.05
		end
		if UIS:IsKeyDown(Enum.KeyCode.R) then
			--print"Bucket up"
			hoist.TargetPosition = 0
		end
		if UIS:IsKeyDown(Enum.KeyCode.F) then
			--print"Bucket down"
			hoist.TargetPosition = -150
		end
		if UIS:IsKeyDown(Enum.KeyCode.Q) then
			--print"Bucket opening"
			inner.DesiredAngle = math.rad(-60)
			outer.DesiredAngle = math.rad(-60)
		end
		if UIS:IsKeyDown(Enum.KeyCode.E) then
			--print"Bucket closing"
			inner.DesiredAngle = 0
			outer.DesiredAngle = 0
		end
		if UIS:IsKeyDown(Enum.KeyCode.L) then
			if not debounce then
				debounce = true
				--print"Crane lights"
				if l5.Enabled == true then
					l1.Material = "Slate"
					l2.Enabled = false
					l3.Enabled = false
					l4.Enabled = false
					l5.Enabled = false
				else 
					l1.Material = "Neon"
					l2.Enabled = true
					l3.Enabled = true
					l4.Enabled = true
					l5.Enabled = true
				end
				wait(.4)
				debounce = false
			end
		end
	end
end)		

UIS.InputEnded:connect(function(InputObject,gameProcessedEvent)
	if jib then
		if not UIS:IsKeyDown(Enum.KeyCode.W) then
			trolley.TargetPosition = trolley.CurrentPosition
		end
		if not UIS:IsKeyDown(Enum.KeyCode.S) then
			trolley.TargetPosition = trolley.CurrentPosition
		end
		if not UIS:IsKeyDown(Enum.KeyCode.A) then
			jib.AngularVelocity = 0
		end
		if not UIS:IsKeyDown(Enum.KeyCode.D) then
			jib.AngularVelocity = 0
		end
		if not UIS:IsKeyDown(Enum.KeyCode.R) then
			hoist.TargetPosition = hoist.CurrentPosition
		end
		if not UIS:IsKeyDown(Enum.KeyCode.F) then
			hoist.TargetPosition = hoist.CurrentPosition
		end
		if not UIS:IsKeyDown(Enum.KeyCode.Q) then
			inner.DesiredAngle = inner.CurrentAngle
			outer.DesiredAngle = inner.CurrentAngle
		end
		if not UIS:IsKeyDown(Enum.KeyCode.E) then
			inner.DesiredAngle = inner.CurrentAngle
			outer.DesiredAngle = inner.CurrentAngle
		end
	end
end) ```

Aha moment!!

In the second script at the end of the InputEnded function I had to call the InputBegan function again.

local function Input(InputObject,gameProcessedEvent)
    if jib then
        --stuff
    end    
end		

UIS.InputEnded:connect(function(InputObject,gameProcessedEvent)
    if jib then
        --stuff
        Input()  -- sends it back to the Input function to keep the working keys doing their job.
    end
end)

UIS.InputBegan:Connect(Input)