I wrote code of decreasing velocity of LinearVelocity, it works almost correctly but the problem is the speed of decreasing velocity changes(depending on FPS) so it makes LinearVelocity acting further which isnt supposed to be.
My code:
local max_power = (dir == "left" and Vector3.new(-80, 0, 0)) or (dir == "right" and Vector3.new(80, 0, 0))
local LinearVelocity = Instance.new("LinearVelocity", char:FindFirstChild("HumanoidRootPart"))
LinearVelocity.Attachment0 = char:FindFirstChild("HumanoidRootPart"):FindFirstChild("RootAttachment")
LinearVelocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
LinearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
LinearVelocity.ForceLimitMode = Enum.ForceLimitMode.PerAxis
LinearVelocity.MaxAxesForce = Vector3.new(30000, 0, 30000)
LinearVelocity.VectorVelocity = max_power
game.Debris:AddItem(LinearVelocity, 0.3)
table.insert(temp, LinearVelocity) -- adds variable to global variable to clean for exception
table.insert(temp, task.spawn(function()
local time_decreasing = 0.3
local percents = 1
local timer = tick()
repeat
game:GetService("RunService").Heartbeat:Wait()
LinearVelocity.VectorVelocity = Vector3.new(max_power.X*percents, max_power.Y*percents, max_power.Z*percents)
if (percents-0.01) > 0 then
percents-=0.01
else
percents = 0
end
print(percents)
until (LinearVelocity.Enabled == false or LinearVelocity == nil or tick() - timer >= time_decreasing) and percents <= 0
end))