How can I detect when I player presses W while in the vehicleSeat?

I’m making a boat, and when you press W I am trying to make it go forward.
The script I have so far is:
(Thanks to nicemike40 for making some of it)

local UIS = game:GetService("UserInputService")
local seat = script.Parent
local direction = 3
local invehicleseat = false
local MotorBoat = game.Workspace.motorboat.DefaultMotorBoat
seat:GetPropertyChangedSignal("Throttle"):Connect(function()
	print("Seat throttle changed to: " .. seat.Throttle)
	invehicleseat = true
	wait(0.2)
	invehicleseat = false
	
end)

seat:GetPropertyChangedSignal("Steer"):Connect(function()
	print("Seat steer changed to: " .. seat.Steer)
end)
UIS.InputBegan:Connect(function()
	if invehicleseat == true then
		while UIS:IsKeyDown(Enum.KeyCode.E) do 
			print("e is being held")
			wait()
			if seat:GetPropertyChangedSignal("Throttle") then
				print("Test if this works")
			end
		end	
	end
end)

How can I make this work? I don’t get any error mesages.

1 Like

You can use Throttle and Steer to know where the player wants to go. If Throttle is 1 then the player is pressing W and if its -1 then player is pressing S. For the steer, if the value is 1 then the player is pressing A and if its -1 then the player is pressing D. If the values are 0 then the player isnt pressing any of these keys.

Have a look at this for more info.

You can use the Occupant property:

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
    --fires whenever a player leaves or enters a vehicle seat
    if (seat.Occupant) then
        --User is in seat, fire the userInput event
    end
end)

Please use this above then trying to determine whether a player is in the seat or not :+1:

And you can also use:

UIS.InputBegan --fires whenever input is received
--and
UIS.InputEnded --fires whenever a key is released

Instead of :IsKeyDown().

Wait, should this be in a local script or a server script?

I’m sorry, I was sleeping.
A local script when you’re using UserInputService.

1 Like