I’m trying to make a car. But it won’t go straight it just turns.
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