How can I detect when a player presses a button and is in a car?

So im trying to make a plane, and planes go up and down, so I was wondering how u make it so if the player presses a certain button the plane goes up/down.
Any help would be appreciated

userinputservice = game:GetService(“UserInputService”)
userinputservice.InputBegan:Connect(function(inp , gpe)
if gpe == false and inp.KeyCode == – [[desired Key]] do
code here
end
end)
There are many ways to move it up and down and control how much.
You can tween the plane’s cframe to where you want.
You can also use a body position.
Or using run Service you can check if a certain key is down and if it is pressed then make it go up/ down.

kinda worked but it still does it to the plane even if im not sitting in it.

1 Like

You could check if the player is sitting using the occupant property of the seat. If there is no humanoid, it’s nil. Otherwise, it’s the humanoid of the character sitting in it (I think).

Then you can simply check if the player is sitting or not.

: property of humanoid.

1 Like

why did i not think of that XD