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 :)
Lagging with a WalkSpeed of 32? If you are in a modeled environment, your PC just can not seem to keep up (although 32 is still really low). Test it on only a Baseplate. You should easily be able to get speeds up to 1000 or more.
Enable the micro Profiler and watch your Framerate.
My current guess: Your PC is too slow.
Edit: The script itself is fine