My car not going straight

I’m trying to make a car. But it won’t go straight it just turns.


Image from Gyazo

if i press A before pressing W it turns less aggressively for some weird reason

This is the LocalScript:

local remote = game:GetService("ReplicatedStorage").PlayerVehicleControls

local riding = nil

local speed = 0

remote.OnClientEvent:Connect(function(isRiding, seat)
	if isRiding then
		riding = seat
	else
		if riding == seat then
			riding = nil
		end
	end
end)

game:GetService("RunService").Heartbeat:Connect(function()
	if riding then
		local base = riding.Parent.Base
		
		local wheels = {
			Left = {
				Front = base.FrontLeftWheelHinge,
				Back = base.BackLeftWheelHinge
			},
			Right = {
				Front = base.FrontRightWheelHinge,
				Back = base.BackRightWheelHinge
			}
		}
		
		speed = riding.Throttle * riding.MaxSpeed
		
		if riding.Steer == -1 then
			print("LEFT")
			
			wheels.Left.Front.AngularVelocity = speed
			wheels.Left.Back.AngularVelocity = speed
			
			wheels.Right.Front.AngularVelocity = -speed
			wheels.Right.Back.AngularVelocity = -speed
		end
		if riding.Steer == 1 then
			print("RIGHT")
			
			wheels.Left.Front.AngularVelocity = -speed
			wheels.Left.Back.AngularVelocity = -speed
			
			wheels.Right.Front.AngularVelocity = speed
			wheels.Right.Back.AngularVelocity = speed
		end
		if riding.Steer == 0 then
			print("STRAIGHT")
			
			wheels.Left.Front.AngularVelocity = speed
			wheels.Left.Back.AngularVelocity = speed
			
			wheels.Right.Front.AngularVelocity = speed
			wheels.Right.Back.AngularVelocity = speed
		end
		
		print(speed)
	end
end)

And the server script

local Players = game:GetService("Players")

local seat = script.Parent

local Remote = game:GetService("ReplicatedStorage").PlayerVehicleControls

local function setCarOwnership(ownership)
	for _, v in pairs(seat:GetDescendants()) do
		if v:IsA("BasePart") then
			v:SetNetworkOwner(ownership)
		end
	end
end

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local newOccupant = seat.Occupant
	
	if newOccupant then
		local Player = Players:GetPlayerFromCharacter(newOccupant.Parent)
		
		if Player then
			setCarOwnership(Player)
			return Remote:FireClient(Player, true, seat)
		end
		warn("Failed to find Player from "..newOccupant.Parent.Name)
	else
		setCarOwnership()
		Remote:FireAllClients(false, seat)
	end
end)

Thanks for your help!

I am aware that you can turn around in tank drive without holding down throttle

2 Likes

I’m not entirely sure how you’ve seen up your framework here, but it looks like your relating VehicleSeat.Steer (turning) to moving forward, when it should be linked to Throttle only.

1 Like

The speed is linked to VehicleSeat.Throttle

1 Like

It is, but you’re setting AngularVelocity based off of riding.Steer for some reason. This isnt the problem with your code but it’s a very odd thing

1 Like

How am i doing that? I’m trying to do tank-drive

1 Like

Check to make sure all the Attachments are facing the right way round
and that the AngularVelocities aren’t fighting against eachother