Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I reduce lag in this script?

Asked by 7 years ago
local engine = script.Parent.Parent.Engine
local spd = script.Parent.Parent.VehicleSeat.MaxSpeed/200
local position = engine.Position

function onChildAdded()
moving = true
script.Parent.Anchored = false
end

function onChildRemoved()
moving = false
engine.Velocity = Vector3.new(0,0,0)
end

script.Parent.Parent.VehicleSeat.ChildRemoved:connect(onChildRemoved)
script.Parent.Parent.VehicleSeat.ChildAdded:connect(onChildAdded)

while true do
    wait(.1)
    if moving then
    direction = engine.CFrame.lookVector 
    position = position + spd*2.5*direction
    errorl = position - engine.Position
    engine.Velocity = spd*errorl
    engine.RotVelocity = Vector3.new(0, 0, 0)
    end
end 

Anyone know how to reduce lag in this script?

Answer this question