Scripting a Movement System That Slows Down Player if they Miss a Jump

Hey guys, so I’m trying to make my own Nextbot game, and currently I’m scripting the movement system that a lot of the games have. I want to code a system that accelerates the player as they continue to jump and walk, but if they miss a jump or stop jumping, they slow down.

Now my current problem is that I don’t know how to make sure they’ve haven’t missed a jump. I’ve tried my best, but one thing I’ve noticed is that you can just hold down the jump key and then never miss a jump.

Here’s my current code for reference:

local player = game.Players.LocalPlayer
repeat wait(1) until player.Character 
local char = player.Character
local hum = char:WaitForChild("Humanoid")

local runService = game:GetService("RunService")
local cooldown = false

runService.RenderStepped:Connect(function()
		
	if player.isInfected.Value == false then
		
		if hum.MoveDirection.Magnitude >= 1 then

			if hum.Jump == true and hum.WalkSpeed < 60 then

				if (hum.WalkSpeed + 3) < 60 then

					hum.WalkSpeed += 1.5

				else

					hum.WalkSpeed = 60

				end

			elseif hum.WalkSpeed < 35 then

				if (hum.WalkSpeed + .1) < 35 then

					hum.WalkSpeed += .1

				else

					hum.WalkSpeed = 35

				end

			end

			if hum.WalkSpeed > 35 then

				if hum.Jump == false and char.HumanoidRootPart.Velocity.Y <= 0 and cooldown == false then

					cooldown = true

				elseif hum.Jump == false and char.HumanoidRootPart.Velocity.Y >= 0 and char.HumanoidRootPart.Velocity.Y < 1 and cooldown == true then

					hum.WalkSpeed -= 40
					cooldown = false

				else

					print(tostring(char.HumanoidRootPart.Velocity.Y))

				end

			end

			if hum.WalkSpeed < 5 then

				hum.WalkSpeed = 5

			end

			wait(1)

		elseif hum.MoveDirection.Magnitude == 0 then

			hum.WalkSpeed = 16

		end
		
	end
	
end)

Just a note, I added the cooldown as of course, I didn’t want it to be too sensitive and make people slow down if they don’t hit the jump in the exact millisecond.

I haven’t seen many other solutions (maybe I didn’t search up the right thing), but please let me know if you have any ideas, thanks! :smiley: