# Part Vehicle Model

As the title says I created a simple vehicle script. It’s just a moving part basically and has most of the basic parts of a vehicle for anyone interested in learning how to move a part and create something vehicle like.

As for this script feel free to use it in any of your projects I think this could be useful to some people so I’m gonna post this here

Source Code
``````--[[
Simple vehicle script made by fireblast3228
Has rotation and movements can accelerate and can decelerate before stoping
Created: 11/12/2020
Edited: Never(Feel free to make your own edits)
]]

local uis = game:GetService("UserInputService") -- Input Detection
local bv = Instance.new("BodyVelocity",workspace.Part) -- Creates the movement
local accelerate = false -- Detects if car is moving
local speed = 0 -- Speed
bv.Velocity = Vector3.new() -- Make the body velocity 0,0,0
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
local bg = Instance.new("BodyGyro",workspace.Part) -- Maintain rotation
bg.CFrame = CFrame.new() -- Makes body gyro CFrame 0,0,0
bg.MaxTorque = Vector3.new(math.huge,math.huge,math.huge) -- Maintain Rotation
local part = workspace.Part -- Part

uis.InputBegan:Connect(function(input,istyping)
if part.Seat.Occupant ~= game.Players.LocalPlayer.Character.Humanoid then return end -- Checks if player is in seat
if not istyping then
if input.KeyCode == Enum.KeyCode.W then -- Input
accelerate = true
repeat
speed = speed + 1
bv.Velocity = part.CFrame.LookVector * speed -- Speed Increase
bg.CFrame = part.CFrame
wait(.5)
until accelerate == false
end
if input.KeyCode == Enum.KeyCode.S  then
accelerate = true
if speed > -300 then
repeat
speed = speed - 1
bv.Velocity = part.CFrame.LookVector * speed -- Speed Increase
bg.CFrame = part.CFrame
print(speed)
print(speed < -300)
wait(.5)
until accelerate == false or speed < -300 -- Speed limit for backwards moving
else
speed = 0
end
end
if input.KeyCode == Enum.KeyCode.A then
bg.CFrame = part.CFrame * CFrame.Angles(0,math.rad(15),0) -- Rotation(Okay its trash I get it)
end
if input.KeyCode == Enum.KeyCode.D then
bg.CFrame = part.CFrame * CFrame.Angles(0,math.rad(-15),0)-- Rotation(Okay its trash I get it) if you want a better one edit it yourself I'm not doing it
end
end
end)

uis.InputEnded:Connect(function(input,istyping)
if part.Seat.Occupant ~= game.Players.LocalPlayer.Character.Humanoid then return end
if not istyping then
if input.KeyCode == Enum.KeyCode.W then
bg.CFrame = part.CFrame
accelerate = false
repeat wait()
bv.Velocity = part.CFrame.LookVector * speed  -- Decelerate
speed = speed - 1
until
speed == 0 or speed < 0 or accelerate == true
if speed <= 0 and accelerate == false then
speed = 0
bv.Velocity = Vector3.new()
end
end
if input.KeyCode == Enum.KeyCode.S  then
bg.CFrame = part.CFrame
accelerate = false
if speed < 0 then
repeat wait()
bv.Velocity = part.CFrame.LookVector * speed
speed = speed + 1
until speed > 0 or accelerate == true
if speed > 0 and accelerate == false then -- Decelerate
speed = 0
bv.Velocity = Vector3.new()
end
end
end
end
end)
``````

Source file:
Simple Vehicle.rbxl (24.6 KB)