Hello,
I am trying to figure out how to set the limit to how much I can accelerate or decelerate (Reverse) however, it will hit that limit and then loop out of control and the speed will just continue to increase (positively and negatively) regardless and I am not sure how to stop it or rather put a speed limit on it. Any guidance would be greatly appreciate.
MaxSpeed = 120
MinSpeed = -10
local EngineOn = false
local Active = false
local SpeedUp = true
local SpeedDown = true
game:GetService("UserInputService").InputBegan:Connect(function(inputObj, gameProccessedEvent)
if not gameProccessedEvent then
if inputObj.KeyCode == Enum.KeyCode.LeftControl and EngineOn and Active and SpeedUp and Vehicleseat.Velocity.X <= MaxSpeed then
--if EngineNoise.Pitch <= MaxNoise then
--end
SpeedUp = false
while SpeedUp == false do
IncreaseSpeedEvent:FireServer(Vehicleseat, EngineNoise, MaxNoise)
wait()
end
end
if inputObj.KeyCode == Enum.KeyCode.Z and EngineOn and Active and SpeedUp and Vehicleseat.Velocity.X >= MinSpeed then
--if Speed.Value > -5 then
--if EngineNoise.Pitch >= MinNoise then
--end
SpeedDown = false
while SpeedDown == false do
DecreaseSpeedEvent:FireServer(Vehicleseat, EngineNoise, MinNoise)
wait()
end
end
end
end)
game:GetService("UserInputService").InputEnded:Connect(function(inputObj, gameProccessedEvent)
if not gameProccessedEvent then
if inputObj.KeyCode == Enum.KeyCode.LeftControl and SpeedUp ~= true and Vehicleseat.Velocity.X < MaxSpeed and EngineOn then
SpeedUp = true
IncreaseSpeedEvent:FireServer(Vehicleseat, EngineNoise, MaxNoise)
end
if inputObj.KeyCode == Enum.KeyCode.Z and SpeedDown ~= true and Vehicleseat.Velocity.X > MinSpeed and EngineOn then
SpeedDown = true
DecreaseSpeedEvent:FireServer(Vehicleseat, EngineNoise, MinNoise)
elseif ConfigFolder.Speed.Value < MinSpeed then
ConfigFolder.Speed.Value = -5
end
end
end)