I am trying to make my own car using sleitnick tutorial, while doing so I realized that my car cannot move. It can only turn. I tried changing the torque, checking if any parts are anchored or not which they aren’t. This is the car I am using:
And this is the script:
local:
local car = script:WaitForChild("Car").Value
local stop = script:WaitForChild("Stop")
local seat = car.Body.VehicleSeat
local attFL = car.Chassis.Platform.AttachmentFrontLeft
local attFR = car.Chassis.Platform.AttachmentFrontRight
local clyFL = car.Chassis.Platform.CylindricalFrontLeft
local clyFR = car.Chassis.Platform.CylindricalFrontRight
local clyRL = car.Chassis.Platform.CylindricalRearLeft
local clyRR = car.Chassis.Platform.CylindricalRearRight
local maxSteer = 25
local steer = 0
local throttle = 0
local heartbeat
local function Update(dt)
--Steer;
local steerGoal = seat.SteerFloat * maxSteer
steer = steer + (steerGoal - steer) * math.min(dt * seat.TurnSpeed,1)
attFL.Orientation = Vector3.new(0,steer,-90)
attFR.Orientation = Vector3.new(0,steer,-90)
--Throttle;
local throttleGoal = seat.ThrottleFloat
throttle = throttle + (throttleGoal - throttle) * math.min(dt * seat.TurnSpeed,1)
local torque = seat.Torque
local speed = seat.MaxSpeed * throttle
clyFL.MotorMaxTorque = torque
clyFR.MotorMaxTorque = torque
clyRL.MotorMaxTorque = torque
clyRR.MotorMaxTorque = torque
clyFL.AngularVelocity = speed
clyFR.AngularVelocity = -speed
clyRL.AngularVelocity = speed
clyRR.AngularVelocity = -speed
end
local function Start()
print("Start client")
heartbeat = game:GetService("RunService").Heartbeat:Connect(Update)
end
local function Stop()
print("Stop client")
heartbeat:Disconnect()
script:Destroy()
end
Start()
if (stop.Value) then Stop()return end
stop.Changed:Connect(function(shouldStop)
if (not shouldStop) then return end
Stop()
end)
server:
local car = script.Parent
local seat = car.Body.VehicleSeat
local body = car.Body.Body
local physicsService = game:GetService("PhysicsService")
local defaultCollisionGroup = "Default"
local characterCollisionGroup = "Character"
local cooldown = 0
local occupiedPlayer
local occupiedClientScript
local carClientScript = script.CarClient
local function CoolDown(duration)
local cooldownTag = tick()
cooldown = cooldownTag
delay(duration,function()
if (cooldown == cooldownTag) then
cooldown = 0
end
end)
end
local function SetCharacterCollision(character,shouldCollide)
local group = (shouldCollide and defaultCollisionGroup or characterCollisionGroup)
for _,part in ipairs(character:GetChildren()) do
if (part:IsA("BasePart")) then
part.Massless = not shouldCollide
physicsService:SetPartCollisionGroup(part,group)
end
end
end
local function BodyTouched(part)
if (seat.Occupant or cooldown ~= 0) then return end
local character = part.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if (not player) then return end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if (not humanoid) then return end
seat:Sit(humanoid)
occupiedPlayer = player
SetCharacterCollision(character,false)
car.PrimaryPart:SetNetworkOwner(player)
occupiedClientScript = carClientScript:Clone()
occupiedClientScript.Car.Value = car
occupiedClientScript.Parent = player.Backpack
CoolDown(1)
end
local function OccupantChanged()
if (seat.Occupant) then return end
if (occupiedPlayer.Character) then
SetCharacterCollision(occupiedPlayer.Character,true)
end
if (occupiedClientScript.Parent) then
occupiedClientScript.Stop.Value = true
local client = occupiedClientScript
delay(3,function()
client:Destroy()
end)
end
car.PrimaryPart:SetNetworkOwnershipAuto()
occupiedPlayer = nil
occupiedClientScript = nil
CoolDown(3)
end
body.Touched:Connect(BodyTouched)
seat:GetPropertyChangedSignal("Occupant"):Connect(OccupantChanged)