Hi I made ships in my game and they use body position and body BodyVelocity to move. But there is a problem. The ships have a speed limit which is 15 when going forward but when going back the limit doesnt work and you can infinitely accelerate.

script.Parent.MaxSpeed = 15
maxspeed  =script.Parent.MaxSpeed
script.Parent.BodyPosition.position = script.Parent.Position
script.Parent.BodyGyro.cframe = script.Parent.CFrame
value1 = 0
while true do
    wait()
    if script.Parent.Throttle== 1 then
        if value1 < maxspeed then value1 = value1+1 end
        script.Parent.Parent.Driving.Value = true
        script.Parent.BodyVelocity.velocity = script.Parent.CFrame.lookVector*value1
        script.Parent.Parent.Left.Value = false
        script.Parent.Parent.Right.Value = false
    end
    if script.Parent.Throttle == 0 then 
        script.Parent.Parent.Driving.Value = false
        script.Parent.BodyVelocity.velocity = script.Parent.CFrame.lookVector*value1
        script.Parent.Parent.Left.Value = false
        script.Parent.Parent.Right.Value = false
    end
    if script.Parent.Throttle== -1 then
        if value1< maxspeed then value1 = value1-1 end
        if value1 == maxspeed then value1 = value1-1 end
        script.Parent.Parent.Driving.Value = true
        script.Parent.BodyVelocity.velocity = script.Parent.CFrame.lookVector*value1
        script.Parent.Parent.Left.Value = false
        script.Parent.Parent.Right.Value = false
    end
if script.Parent.Steer == 1 then
script.Parent.BodyGyro.cframe = script.Parent.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(0,-.01,0)
script.Parent.Parent.Driving.Value = true
script.Parent.Parent.Right.Value = true
script.Parent.Parent.Left.Value = false
end
if script.Parent.Steer == -1 then
script.Parent.BodyGyro.cframe = script.Parent.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(0,.01,0)
script.Parent.Parent.Driving.Value = true
script.Parent.Parent.Left.Value = true
script.Parent.Parent.Right.Value = false
end
end

Here is the script. I hope someone could help me with this problem. Thanks for your time!

1 comment

0

I've never tried something like this before, but it may be because when its going backwards its creating negative body velocity, while your max velocity for it is a positive amount, so it wont have a max