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

How do I fix this speed bug with my vechicle?

Asked by 2 years ago

This is the code

local lw1 = script.Parent.Parent.LW1
local lw2 = script.Parent.Parent.LW2
local rw1 = script.Parent.Parent.RW1
local rw2 = script.Parent.Parent.RW2
local steer = script.Parent.Parent.Steer
speed = 80
script.Parent.Changed:Connect(function(property)
    lw1.AngularVelocity = speed * script.Parent.Throttle
    lw2.AngularVelocity = speed * script.Parent.Throttle
    rw1.AngularVelocity = -speed * script.Parent.Throttle
    rw2.AngularVelocity = -speed * script.Parent.Throttle
    steer.TargetAngle = 10 * script.Parent.Steer

    if script.Parent.Parent.VehicleSeat.Occupant then
        script.Parent.Parent.Engine["Car Engine"]:Play()
        local lastPos = workspace.cae12.Engine.Position
        while true do
            wait(0.2)
            local velocity = (workspace.cae12.Engine.Position - lastPos)
            lastPos = workspace.cae12.Engine.Position
            script.Parent.Parent.Engine["Car Engine"].Pitch = 1 + velocity.Magnitude/100
        end
    else
        script.Parent.Parent.Engine["Car Engine"]:Stop()
    end
end)

But there's a few bugs. I want that the sound continues playing even when the car isn't moving, but just standing still with me inside. And also when it reaches maximum speed, the sound stops playing - how do I fix this?

Answer this question