Coyote jumps (working on PC)

so I make coyote jumps by myself (kinda bad) because there was no post about these jumps before but now there is
here is the script I made
if there is a better version, pls tell me ;-;
(put it in StarterCharacterScripts)
robloxapp-20230514-2141599.wmv (3.2 MB)

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")

local uis = game:GetService("UserInputService")
local cas = game:GetService("ContextActionService")
local runService = game:GetService("RunService")

local loopConnection 
local coyoteTime = 0.5
local coyoteTimeCounter = coyoteTime

humanoid.StateChanged:Connect(function(old,new)
	if old == Enum.HumanoidStateType.Landed and new == Enum.HumanoidStateType.Running then 
		if loopConnection then loopConnection:Disconnect() end 
		coyoteTimeCounter = coyoteTime 
	elseif old == Enum.HumanoidStateType.Running and new == Enum.HumanoidStateType.Freefall then 
		loopConnection = runService.Heartbeat:Connect(function(deltaTime)
			coyoteTimeCounter -= deltaTime
		end)
	end 
end)

local function onJump()
	if humanoid and coyoteTimeCounter > 0 then
		coyoteTimeCounter = 0
		humanoid:ChangeState(Enum.HumanoidStateType.Jumping,true)
	end
end

cas:BindAction("jumpAction",onJump,false,Enum.KeyCode.Space)
5 Likes

Neat! I’m happy to see that someone on Roblox eventually talked about some sort of coyote mechanics, was going to think I was the only one that had this strange interest. Roblox already has something similar to this built in I believe, just to a way smaller extent (much stricter timeframe). Messed with it before to find out that Roblox still lets humanoids jump even after their FloorMaterial has changed to air and their velocity shows that they’re falling.

A few suggestions to input detection though. UserInputService has a JumpRequest event (docs reference), so using that would allow it to work on multiple different platforms/devices. A downside to this however is that it fires multiple times after you press/hold spacebar just once. I don’t imagine that it would affect you much though, since preforming a coyote jump disallows you from jumping again midair. If you want to stick to ContextActionService, I would suggest using InputStates to make sure it only triggers when you’ve pressed space and not when you’ve let go of space (or vice versa).

2 Likes

yes, i encoutered some weird double j.umps when I tested the jump but don’t know how to fix it so i will try your solution anyways
thanks for your respond.