No auto-jump after unbinding an action that disables space?

So I want to make an area in which the spacebar does absolutely nothing by using ContextActionService. The problem I’m facing is that when a player leaves the area, the player doesn’t start auto-jumping after the action binding that disables space is unbound.

For the purpose of simplification, here’s a basic setup that demonstrates the issue:

local contextActionService = game:GetService("ContextActionService")
local debounce = false
workspace.Part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not debounce then
		debounce = true
		contextActionService:BindAction("NoJump", function() end, false, Enum.KeyCode.Space, Enum.PlayerActions.CharacterJump)
		contextActionService:UnbindAction("NoJump")
		wait(1)
		debounce = false
	end
end)

What happens is that when a player jumps through the part while holding space, they don’t continue auto-jumping when they hit the ground, and must let go of space and hold it again before auto-jump works.

How can I make it so that the player starts auto-jumping without needing to let go of space and hold it again?

I have tried various priority levels for the action binding, and there were no differences to the result. Additionally, disabling Enum.HumanoidStateType.Jumping on the humanoid is not what I’m looking for, as there may be water inside the space does nothing area, and when space is held while a player is inside water, a force pushes them upwards even when jumping is disabled. As far as I know, there isn’t a way to disable this mechanic.

2 Likes

A workaround I came up with is temporarily creating a custom auto-jump by detecting when the player hits the ground or lets go of space

local contextActionService = game:GetService("ContextActionService")
local userInputService = game:GetService("UserInputService")

local humanoid = game.Players.LocalPlayer.Character.Humanoid

local connection1
local connection2

local function disconnect()
	connection1:Disconnect()
	connection2:Disconnect()
	connection1 = nil
	connection2 = nil
end

local debounce = false
workspace.Part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and not debounce then
		debounce = true
		if connection1 then
			disconnect()
		end
		contextActionService:BindAction("NoJump", function() end, false, Enum.KeyCode.Space, Enum.PlayerActions.CharacterJump)
		wait(2) --placeholder for what would count as leaving the area
		contextActionService:UnbindAction("NoJump")
		if userInputService:IsKeyDown(Enum.KeyCode.Space) then
			if humanoid.FloorMaterial ~= Enum.Material.Air then
				humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			end
			connection1 = humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
				if humanoid.FloorMaterial ~= Enum.Material.Air and userInputService:IsKeyDown(Enum.KeyCode.Space) then
					humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
				end
			end)
			connection2 = userInputService.InputEnded:Connect(function(key, gameProcessed)
				if key.KeyCode == Enum.KeyCode.Space and not gameProcessed then
					disconnect()
				end
			end)
		end
		wait(1)
		debounce = false
	end
end)

humanoid.Died:Connect(disconnect)

I’m sure there are better solutions out there, so please share if you know any :slight_smile:
I’ll select this as the solution until then

2 Likes