Ok so i'm making a movement system and I started first by adding momentum. But when you reach max momentum it starts lagging pretty severely.
Here's the code (It's in StarterCharacterScripts and is a local script)
local Plr = game.Players.LocalPlayer
local Char = Plr.Character
local Humanoid = Char:FindFirstChild("Humanoid")
local Sprinting = false
local UIS = game:GetService("UserInputService")
local RunKey = Enum.KeyCode.LeftShift
local Momentum = 0
local MaxMomentum = 1
local DefaultSpeed = 16
UIS.InputBegan:Connect(function(input,gpe)
if gpe then return end
if input.KeyCode == RunKey then
Sprinting = true
task.spawn(function()
while Sprinting do
task.wait()
if Momentum >= MaxMomentum then
Momentum = MaxMomentum
else
task.wait(0.5)
Momentum += 0.1
end
end
end)
end
end)
UIS.InputEnded:Connect(function(input,gpe)
if gpe then return end
if input.KeyCode == RunKey then
Sprinting = false
Momentum = 0
end
end)
while wait() do
if Sprinting then
Humanoid.WalkSpeed = (DefaultSpeed*(Momentum+1))
else
Humanoid.WalkSpeed = DefaultSpeed
end
end
If you can help that would be greatly appreciated :)

1 comment
Oh, once i test on a baseplate it works fine either my pc is too slow or it's another script in the game messing it up. Thanks!