How would i script a car to move

Hey, i’ve made a car in blender and would like help to script it, for example ‘E’ to enter the car, and using ‘W,A,S,D’ to make it move.
If you know any helpful videos, please leave a link in the replys.

Much appreciated.
:slight_smile:

3 Likes

For the sit, you could use the <SeatPart>:Sit() function for example,

local CarS = script.Parent:FindFirstChild(“DriveSeat”)
CarS:Sit(Character.Humanoid)

You will just need the Humanoid of the Target Character.

1 Like

would that be a local script or a normal script

1 Like

I would use a LocalScript and UserInputService.InputBegan to see if someone pressed E and if they did do :Sit(Character.Humanoid).

1 Like

To script the player pressing “E” to get into the car, use UserInputService.
And for the car, you don’t need to script anything on how they drive it, but! If you want to have acceleration sounds, I’d check out This Post.
Here is a tutorial on how to make / rig a car:

I hope some of this helped!

I found some videos for E to sit in a car / seat:



-- In order to use the InputBegan event, the UserInputService service must be used
local UserInputService = game:GetService("UserInputService")
 
-- A sample function providing multiple usage cases for various types of user input
UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		local keyPressed = input.KeyCode
		print("A key is being pushed down! Key:",input.KeyCode)
	elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
		print("The left mouse button has been pressed down at",input.Position)
	elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
		print("The right mouse button has been pressed down at",input.Position)
	elseif input.UserInputType == Enum.UserInputType.Touch then
		print("A touchscreen input has started at",input.Position)
	elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
		print("A button is being pressed on a gamepad! Button:",input.KeyCode)
	end
 
	if gameProcessed then
		print("\tThe game engine internally observed this input!")
	else
		print("\tThe game engine did not internally observe this input!")
	end
end)

That’s the script i have so far.

1 Like

I think that you’d want to use

Enum.KeyCode.E

Something like that, because the current one has nothing that can detect what to do when the player presses E, you could try to find the key with your current script though.

2 Likes

What line would be in (the script is a total of 24 lines)

1 Like

Here, I’ve modified your script to help you with your goal:

-- In order to use the InputBegan event, the UserInputService service must be used
local UserInputService = game:GetService("UserInputService")
 
-- A sample function providing multiple usage cases for various types of user input
UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		local keyPressed = input.KeyCode
		if input.KeyCode == Enum.KeyCode.E then
		print("E Was Pressed")
		--input the seating code here.
		end
	end
end)
2 Likes

I would also check if gameProcessed is true or not because you would not want players to accidentally enter a car while saying something in chat.

2 Likes

That is a good point, but tbh i would be kinda funny

Thanks, i’ll see if it works
(30chars)

Yeah, and connect it with RemoteEvent.

If you prefer video tutorials then watch this

And for the E to enter you would use user input service and get the vehicle seat occupant and change it to the players.