How to make a momentum change

Hello, so what I am trying to achieve is a something similar to this videos

I’d tried this

while true do
	while true do
		if workspace:WaitForChild(game.Players.LocalPlayer.Name).Humanoid.MoveDirection == Vector3.new(0,0,0) then
			
		else
			break
			
		end
		wait()
	end
	local wa = workspace:WaitForChild(game.Players.LocalPlayer.Name)
	wa.Humanoid.WalkSpeed = 0
	for i = 1,16 do
		wa.Humanoid.WalkSpeed = wa.Humanoid.WalkSpeed + 4
		wait(1)
	end
	wa.Humanoid.WalkSpeed = 35
	while true do
		if wa.Humanoid.MoveDirection == Vector3.new(0,0,0) then
		wait(0.025)
			if wa.Humanoid.MoveDirection == Vector3.new(0,0,0) then
				
		for i = 1,16 do
			wa.Humanoid.WalkSpeed = wa.Humanoid.WalkSpeed - 1
		end
				wa.Humanoid.WalkSpeed = 0
				wait()
				break
			end
		end
		wait()
		end
	wait()
end
2 Likes

but I felt that that was kind of choppy. so any other solutions?

Make a new script in StarterPlayerScripts, and paste this:

--//Services
local Players = game:GetService("Players")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

--//Functions
LocalPlayer.CharacterAdded:Connect(function(character)
	Humanoid = character:WaitForChild("Humanoid")
end)

LocalPlayer.CharacterRemoving:Connect(function()
	Humanoid = nil
end)

while true do
	if not Humanoid then
		continue
	end

	while Humanoid.MoveDirection.Magnitude > 0 do
		Humanoid.WalkSpeed += 0.5
		
		task.wait(0.1)
	end
	
	Humanoid.WalkSpeed = 5
	
	task.wait()
end

Thank you, but it seems to not work as well with faster speeds. I 'd changed Humanoid.Walkspeed = 5 to 32, however It still wont seem to work

What do you mean by does not work well with faster speeds? Do you want the speed to increase exponentially depending on how long the player has ran for?

Also, the 5 was for the speed the player was set to if they stopped running.

No, like I want the limit for the speed to be around 30 - 35, but I want it to be slower during the start then over time it starts growing and then once the limit has been touched it stays there until the player stops running.

Oh, try this then:

--//Services
local Players = game:GetService("Players")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

--//Controls
local MaxSpeed = 35

--//Functions
LocalPlayer.CharacterAdded:Connect(function(character)
	Humanoid = character:WaitForChild("Humanoid")
end)

LocalPlayer.CharacterRemoving:Connect(function()
	Humanoid = nil
end)

while true do
	if not Humanoid then
		continue
	end

	while Humanoid.MoveDirection.Magnitude > 0 do
		Humanoid.WalkSpeed = math.min(Humanoid.WalkSpeed + 0.5, MaxSpeed)

		task.wait(0.1)
	end

	Humanoid.WalkSpeed = 5

	task.wait()
end
5 Likes

Also could you help me make it so that the walk animation plays first, and after around 3 seconds it turns into a run animation? I tried it but found a lot of glitches.

Check out my physics character controller. It should have momentum and also use handle the walk to run animation change.

I kind of like the one im using currently. I just need a smooth transition from walking to running

You can just play an animation after 3 seconds passed.

New code: (you will have to edit it a bit)

--//Services
local Players = game:GetService("Players")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local RunAnimation = Humanoid:WaitForChild("Animator"):LoadAnimation(workspace.MyAnimation)

--//Controls
local MaxSpeed = 35
local animationPlaying = false

--//Functions
LocalPlayer.CharacterAdded:Connect(function(character)
	Humanoid = character:WaitForChild("Humanoid")
end)

LocalPlayer.CharacterRemoving:Connect(function()
	Humanoid = nil
end)

while true do
	if not Humanoid then
		continue
	end
	
	local timeElapsed = 0

	while Humanoid.MoveDirection.Magnitude > 0 do
		Humanoid.WalkSpeed = math.min(Humanoid.WalkSpeed + 0.5, MaxSpeed)
		
		if timeElapsed >= 3 and not animationPlaying then
			animationPlaying = true
			RunAnimation:Play()
		end

		task.wait(0.1)
		timeElapsed += 0.1
	end

	Humanoid.WalkSpeed = 5
	
	animationPlaying = false
	RunAnimation:Stop()

	task.wait()
end
2 Likes

Yeah thank you, that worked. This is exactly what I needed.

1 Like