ContextActionService not working for VehicleSeat?

My script does not function at all!

Any ideas why? It prints the print functions but nothing else works.

Which print functions are you referring to?

The print statements “Steer Right”, “Steer Left”, “Throttle Up” and “Throttle Down”.

All of these print but do not actually change the SteerFloat values.

If you print out InputState, does it match what you put in the if statements?

image

Yes, it does.

The values for steer and throttle properties are constantly updated to replicate the input so you need to constantly set the value as with the code you are using now after you set it, it resets to the input’s value. For example if the player is not pressing W/moving the thumbstick the throttle value will be 0 so you need to run a loop and constantly change the value according to your context action.

So, like a coroutine? Or a runservice connection? Which do I use?

Coroutines do not serve the purpose you need, you can use heartbeat.

-- setting throttle to 1
heartbeat = RunService.Heartbeat:Connect(function()
    vehicleSeat.Throttle = 1
end) -- also make sure to call heartbeat:Disconnect() when the player stops holding the context action button otherwise you will run into performance issues

Thank you so much. It works perfectly. Slight issue though. When I press the button and leave it, it works fine. But when i press and hold button, then slide out of the button, InputState does not return Enum.UserInputState.End? Why is that?

Because sliding off the button fires another state event which is Enum.UserImputState.Cancel.

Thank you so much for the help! You’re a lifesaver.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.