Well this is a script from a roblox gear, the hot wheel car, would anyone know what Bit of this controls speed? and/or steering? I can provide a model link if needed, and please don't "thumbs down" just because you don't know how to fix it...

repeat wait() until game.Players.LocalPlayer.Character ~= nil
local D3_EPSILON = 0.001

function CalculateMassRecursive(rootPart)
  local sum = 0
  if rootPart:IsA('BasePart') then
    sum = sum + rootPart:GetMass()
  end
  for _, v in pairs(rootPart:GetChildren()) do
    sum = sum + CalculateMassRecursive(v)
  end
  return sum
end

function RobloxToSAE(vec)
  return Vector3.new(vec.z,vec.x,vec.y)
end

function SAEToRoblox(vec)
  return Vector3.new(vec.y, vec.z, vec.x)
end


function GetTravelVelocity(robloxVelocity)
  return RobloxToSAE(robloxVelocity)
end

local maxForce = Vector3.new()
local camber = 0.01
local wheelRadius = 2
local longStiffness = 0
local latStiffness = 0

local Boat = game.Workspace:WaitForChild("Boat")
local Main = Boat:WaitForChild('Main') --(script and script.Parent) or {Throttle = 1, Steering = 0}

local ThrottleEvent = script:WaitForChild('ThrottleEvent')
local SteeringEvent = script:WaitForChild('SteeringEvent')
local DestroyEvent = script:WaitForChild('DestroyEvent')

local PlayersService = game:GetService('Players')

local Throttle = 0
local Steering = 0

local CurrentOwner = nil

local function SetCurrentOwner(player)
	if not CurrentOwner then
		CurrentOwner = player
		PlayersService.ChildRemoved:connect(function(child)
			if child == CurrentOwner then
				Boat:Destroy()
			end
		end)
	end
end

local LastHard = tick()
ThrottleEvent.Event:connect(function(value)
	if Throttle >= 0 and value < 0 and tick() - LastHard > 1.2 then
		---HardStop:Play()
		LastHard = tick()	
	end
	Throttle = value
end)
SteeringEvent.Event:connect(function(value)
	Steering = value
end)

DestroyEvent.Event:connect(function(value)
	Boat:Destroy()
end)

local Mass = CalculateMassRecursive(Boat) * 9.81 * 5 --(script and script.Parent:GetMass()) or 50

local Fz = (Mass) / 4000----Look in too SPEED

local Boat = {}
local Boat_mt = {__index = Boat}

local Wheel = {}
local Wheel_mt = {__index = Wheel}


function Boat:Create()
  return setmetatable({model = Boat, wheels = {}}, Boat_mt)
end

function Boat:AddWheel(wheelName, wheelClass)
  self.wheels[wheelName] = wheelClass
end

function Boat:GetWheel(wheelName)
  return self.wheels[wheelName]
end

function Boat:GetTravelVelocity()
	return GetTravelVelocity(Main.Velocity)
end

function Boat:Update()
	local forceSum = Vector3.new()
    for wheelName, wheel in pairs(self.wheels) do
		forceSum = forceSum + wheel:Update()
    end

	if math.abs(Main.CFrame.lookVector:Dot(Main.Velocity.unit)) < 0.9 then
	end
end

----------------- WHEEL --------------
function Wheel:Create(wheelOffset, isSteerable, BoatRef)
	local newTorqueObj = Instance.new('BodyThrust')
	newTorqueObj.location = wheelOffset
	newTorqueObj.Parent = Main
	return setmetatable({offset = wheelOffset, canSteer = isSteerable, torqueObj = newTorqueObj, Boat = BoatRef}, Wheel_mt)
end

function Wheel:GetRe()
  return wheelRadius * 2 * math.pi
end

function Wheel:GetOmega()
  if Throttle == 1 then
    return (self.Boat:GetTravelVelocity().magnitude / self:GetRe()) * 1.2
  elseif Throttle == -1 then
    return (self.Boat:GetTravelVelocity().magnitude / self:GetRe()) * 0.8
  else
    return (self.Boat:GetTravelVelocity().magnitude / self:GetRe())
  end
end


function Wheel:GetTorqueObject()
	return self.torqueObj
end

local b0 = 1.65 -- none     
local b1 = 0 -- 1/MegaNewton     
local b2 = Mass --1100 -- 1688 -- 1/K    
local b3 = 0 -- 1/MegaNewton     
local b4 = 229 -- 1/K    
local b5 = 0 -- 1/KN     
local b6 = 0 -- 1/(KN)^2     
local b7 = 0 -- 1/KN     
local b8 = -10 -- none     
local b9 = 0 -- 1/KN
local b10 = 0 -- none
local b11 = 0
local b12 = 0

function Wheel:GetLongitudinalSlip(wheel)
  local V = self.Boat:GetTravelVelocity().magnitude
  -- this is hack to get around divide by zero
  if V == 0 then return 0.1 end
  --print("V" , V)
  local sigma = (self:GetOmega() * self:GetRe() - V) / V
  local slipPercentage = 100 * sigma + b9 * Fz + b10
  --print("Slip in func" , slipPercentage)
  return slipPercentage
end

-- Fx - longitudinal
function Wheel:CalcFx96(slipPercentage)
	
	
--[[ Pacejka96 model
// Calculates longitudinal force (Fx)
// From G. Genta's book, page 63
// Note that the units are inconsistent:
//   Fz is in kN
//   slipRatio is in percentage (=slipRatio*100=slipPercentage)
//   camber and slipAngle are in degrees
// Resulting forces are better defined:
//   Fx, Fy are in N
//   Mz     is in Nm
]]
   local B,C,D,E;
   local Fx;
   local Sh,Sv;
   local uP;
   local FzSquared;
   
  -- Calculate derived coefficients
   FzSquared=Fz*Fz;
   C=b0;
   uP=b1*Fz+b2;
   D=uP*Fz;
   --print("Fz" , Fz)
   -- Avoid div by 0
   if((C>-D3_EPSILON and C<D3_EPSILON) or (D>-D3_EPSILON and D<D3_EPSILON)) then
     B=99999.0;
   else
     B=((b3*FzSquared+b4*Fz)*math.exp(-b5*Fz))/(C*D);
   end
   
   E=b6*FzSquared+b7*Fz+b8;
   Sh=b9*Fz+b10;
   Sv=b11*Fz+b12;
   
   -- Notice that product BCD is the longitudinal tire stiffness
   longStiffness=B*C*D; -- *RR_RAD2DEG;    -- RR_RAD2DEG == *360/2PI
   

   -- Remember maximum longitudal force
   maxForce = (maxForce * Vector3.new(0, 1, 1)) + Vector3.new(D+Sv, 0, 0)

   -- According to this website I think this is the slipPercentage:
  --http://www.miata.net/sport/Physics/Part21.html
  --print("slip" , slipPercentag)
   -- Calculate result force
	Fx=D*math.sin(C*math.atan(B*(1.0-E)*(slipPercentage+Sh)+E*math.atan(B*(slipPercentage+Sh))))+Sv;
 

	return Fx;
end


function Wheel:CalcSideSlip()
  local slipAngle = 0
  if self.Boat:GetTravelVelocity().magnitude > D3_EPSILON then
    local slipVector = Main.CFrame:vectorToObjectSpace(Main.Velocity.unit)
    slipAngle = math.deg(-math.atan2(slipVector.x, slipVector.z))
  end
	-- The function diverges near zero, and freaks out when reversing and turning
	--local localVelocity = Main.CFrame:vectorToObjectSpace(self.Boat:GetTravelVelocity()).Z
	
  -- we are going to hack, and make the sideslip angle be very boolean (key on keyboard are on or off)
  if self.canSteer then
    if Steering == 1 then
      return slipAngle + 30
    elseif Steering == -1 then
      return slipAngle - 30
    end
  end
  return slipAngle
end

--http://www.miata.net/sport/Physics/Part22.html
-- Coefficient Example value Units Description Notes
local a0 = 1.799 --  
local a1 = 0 --   
local a2 = 1688 --   
local a3 = 4140 --    
local a4 = 6.026 -- 
local a5 = 0 --    
local a6 = -0.3589 -- 
local a7 = 1 --     
local a8 = 0 --     
local a9 = -6.111/1000 -- Degree/KN   
local a10 = -3.224/100 -- Degree  
local a11 = 0 --
local a12 = 0 -- 
local a13 = 0 --
local a14 = 0 -- 

-- Fy - lateral
function Wheel:CalcFy96(sideSlip)
	
--[[
// Pacejka 96
// Calculates lateral force
// Note that B*C*D is the cornering stiffness, and
// Sh and Sv account for ply steer and conicity forces
]]
   local B,C,D,E;
   local Fy;
   local Sh,Sv;
   local uP;
   --print(Fz);
   -- Calculate derived coefficients
   C=a0;
   uP=a1*Fz+a2;
   D=uP*Fz;
   E=a6*Fz+a7;
   
   -- Avoid div by 0
   if((C>-D3_EPSILON and C<D3_EPSILON) or (D>-D3_EPSILON and D<D3_EPSILON)) then
     B=99999.0;
   else
     if(a4>-D3_EPSILON and a4<D3_EPSILON) then
       B=99999.0;
     else
       -- Notice that product BCD is the lateral stiffness (=cornering)
       latStiffness=a3*math.sin(2*math.atan(Fz/a4))*(1.0-a5*math.abs(camber));
       B=latStiffness/(C*D);
     end
   end
   
   Sh=a8*camber+a9*Fz+a10;
   --  a111   a112
   Sv=(a11*Fz+a12)*camber*Fz+a12*Fz+a13;
   
   -- Remember maximum lateral force
   maxForce = (maxForce * Vector3.new(1, 0, 1)) + Vector3.new(0, D+Sv, 0)
   
   local 

   -- Calculate result force
   Fy=D*math.sin(C*math.atan(B*(1.0-E)*(sideSlip+Sh)+
      E*math.atan(B*(sideSlip+Sh))))+Sv;

   return Fy;
end


local LastSqueal = tick()
function Wheel:Update()
  --local bf = self.model:FindFirstChild('BodyForce')
  --if bf then
    local slipPercentage = self:GetLongitudinalSlip()
    local fx = self:CalcFx96(slipPercentage)


    local sideSlip = self:CalcSideSlip()
    local fy = self:CalcFy96(sideSlip)

	local localVelocity = Main.CFrame:vectorToObjectSpace(Main.Velocity)
	
	---Idle.Volume = math.min(0.3, math.abs(localVelocity.Z) / 650 + 0.1 + (math.abs(Throttle) / 3))
	---Idle.Pitch = math.min(math.max(0.5, math.abs(localVelocity.Z) / 400 + 0.5) + (math.abs(Throttle) / 18), 1.5)
	if math.abs(sideSlip) < 160 and localVelocity.magnitude > 20 and tick() - LastSqueal > 3.5 then
		delay(1, function()
			----Squeal:Play()
		end)
		LastSqueal = tick()
	end
	
	-- Hack to stop jittering online
	if math.abs(localVelocity.Z) < 2 then
		fy = 0
		Main.Velocity = Main.CFrame:vectorToWorldSpace(Vector3.new(0,localVelocity.Y,localVelocity.Z))
	end

    -- Get the forces into world space for the body forces.
	--local wheelForce = (Main.CFrame:inverse() * SAEToRoblox(Vector3.new(fx,fy,0))) * Vector3.new(1,1,-1)
	local wheelForce = SAEToRoblox(Vector3.new(fx,fy,0)) * Vector3.new(1,1,-1)
	self.torqueObj.force = wheelForce
	return wheelForce
    --bf.force = wheelForce
  --end
end

local theBoat = Boat:Create()

theBoat:AddWheel('FRWheel', Wheel:Create(Vector3.new(Main.Size.X/2,0,Main.Size.Z/2), true, theBoat))
theBoat:AddWheel('FLWheel', Wheel:Create(Vector3.new(-Main.Size.X/2,0,Main.Size.Z/2), true, theBoat))
theBoat:AddWheel('BRWheel', Wheel:Create(Vector3.new(Main.Size.X/2,0,-Main.Size.Z/2), false, theBoat))
theBoat:AddWheel('BLWheel', Wheel:Create(Vector3.new(-Main.Size.X/2,0,-Main.Size.Z/2), false, theBoat))

delay(1, function()
	---Start:Play()
	wait(2)
	---Idle.Looped = false
	---Idle.Looped = true
	while true do
		wait(0.7)
		---Idle:Play()
	end
end)




while true do
  theBoat:Update()
  wait()
end

3 comments

1

The script is too long, no one wants to answer that.

0

Thank you for the +1- <3 Cause you can't help.

0

This isn't constructive. This site is for learning to script, not for telling people how to use free models.