Applying maximum speed doesn't work?
So I'm making a Model
that is hovering on the ground (thanks to a BodyPosition
that's Position
is set a little above the ground and it's MaxForce
is set to 0, 40000, 0) and can be steered. The model consists of a Part
(in which is a Script
, a BodyGyro
, BodyPosition
and a BodyVelocity
) and a VehicleSeat
that is welded to the Part
. The Script
makes it so the signals sent by the player to VehicleSeat
are changing the properties of BodyGyro
and BodyVelocity
. This is how it looks:
01 | local RunService = game:GetService( "RunService" ) |
02 | local part = script.Parent |
03 | local bodyGyro = part.BodyGyro |
04 | local bodyVel = part.BodyVelocity |
05 | local seat = script.Parent.Parent.VehicleSeat |
06 | local goBack, goForward = false , false |
07 | local turnLeft, turnRight = false , false |
12 | seat:GetPropertyChangedSignal( "Occupant" ):Connect( function (char) |
13 | local currentSpeed = 0 |
14 | local currentAngle = 0 |
15 | RunService.Heartbeat:Connect( function (step) |
16 | bodyVel.Velocity = (part.CFrame.LookVector * currentSpeed) |
17 | bodyGyro.CFrame = CFrame.Angles(math.rad( 0 ), math.rad(currentAngle), math.rad( 0 )) |
18 | if seat.Throttle = = - 1 then |
19 | if goBack then return end |
22 | currentSpeed = currentSpeed - 1 |
23 | until seat.Throttle ~ = - 1 or currentSpeed < = maxBack |
25 | elseif seat.Throttle = = 1 then |
26 | if goForward then return end |
29 | currentSpeed = currentSpeed + 1 |
30 | until seat.Throttle ~ = 1 or currentSpeed > = maxForward |
33 | if seat.Steer = = - 1 then |
34 | if turnLeft then return end |
37 | currentAngle = currentAngle + 1 |
38 | until seat.Steer ~ = - 1 |
40 | elseif seat.Steer = = 1 then |
41 | if turnRight then return end |
44 | currentAngle = currentAngle - 1 |
The Model
speeds up fine and rotates fine too, but the maximum speed I applied to it doesn't do anything. The speed easily goes above 20. I tried doing other things to fix it but nothing worked. Thanks for reading.