Hello! I work on my Acceleration System currently for one of my upcoming games, and main way of gaining acceleration, is running on the surface, and main way of losing it is just standing still (or you can use brake to slow down while still moving).
Currently only there my Acceleration Gain/Loss “multiplier” values are being used. It just cuts the wait time between the next time the value will change, and when i tested it, i saw that “task.wait()” can’t handle less than ~0.01 second, so max numbers that have any impact are 1-100 or so. And after observed this script one time, i thought that it works wrong overall, and im curious how can i make it better and more capable?
Script:
task.spawn(function()
while true do
local speed1Percent = (peakSpeed.Value-startSpeed.Value)/100
local FOV1Percent = (peakFOV-startFOV)/100
local customInfo = defaultTweenInfo
customInfo = TweenInfo.new(0.1, defaultTweenInfo.EasingStyle, defaultTweenInfo.EasingDirection)
if humanoid.MoveDirection.Magnitude > 0 and not braking then -- if humanoid moves and not braking
if humanoid:GetState() == Enum.HumanoidStateType.Running then
accelerationPercent.Value = math.clamp(accelerationPercent.Value+1, 0, 100)
customInfo = TweenInfo.new(defaultTweenInfo.Time/accelerationGain.Value, defaultTweenInfo.EasingStyle, defaultTweenInfo.EasingDirection)
end
else
accelerationPercent.Value = math.clamp(accelerationPercent.Value-1, 0, 100)
customInfo = TweenInfo.new(defaultTweenInfo.Time/accelerationLoss.Value, defaultTweenInfo.EasingStyle, defaultTweenInfo.EasingDirection)
end
TS:Create(humanoid, customInfo, {WalkSpeed = math.clamp(startSpeed.Value + (speed1Percent*accelerationPercent.Value), startSpeed.Value, peakSpeed.Value)}):Play()
updateFOVRemote:FireClient(player, defaultTweenInfo.Time/accelerationLoss.Value, math.clamp(startFOV + (FOV1Percent*accelerationPercent.Value), startFOV, peakFOV))
task.wait(customInfo.Time)
end
end)
Any help/advices will be very appreciated! <3