Okay so I have this double jump script that works with computer, but not console
(this is a local script)
So in the code only the first one prints. (print(‘0’))
I tried using jump request but that didn’t work, unless I just did it wrong.
Here is the code block that needs fixing: uis.InputBegan:Connect(function(key, gp)
print(‘passed0’)
if key.KeyCode == Enum.KeyCode.Space or key.KeyCode == Enum.UserInputType.Gamepad1 and not gp then
print(‘Passed1’)
if humanoidRootPart and humanoid then
print(‘Passed2’)
if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
print(‘passed3’)
if jumpUsage >= 1 then
print(‘passed4’)
jumpUsage -= 1
humanoid:ChangeState(Enum.HumanoidStateType.Jumping, true)
humanoid.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Landed then
jumpUsage = 1
end
end)
end
end
end
end
end)
Gamepad1 represents the controller itself, not one of its buttons. If you’re using an Xbox controller, and you want the double jump to work when the player presses A, then you’ll need to use Enum.KeyCode.ButtonA instead
Remove all the UIS checks, JumpRequest doesn’t send input, it just runs when spacebar is pressed.
Here’s a cleaned version:
UserInputService.JumpRequest:Connect(function()
if humanoidRootPart and humanoid and humanoid:GetState() == Enum.HumanoidStateType.Freefall and jumpUsage > 0 then
jumpUsage -= 1
humanoid:ChangeState(Enum.HumaoidStateType.Jumping, true)
end
end)
humanoid.StateChanged:Connect(function(_, newState)
if newState == Enum.HumanoidStateType.Landed then
jumpUsage = 1
end
end
I forgot to mention I did try it, with this line:
if key.KeyCode == Enum.KeyCode.Space or key.KeyCode == Enum.KeyCode.ButtonA and not gp then
and it does not work
Like this?:
uis.JumpRequest:Connect(function()
print(‘Passed1’)
if humanoidRootPart and humanoid then
print(‘Passed2’)
if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
print(‘passed3’)
if jumpUsage >= 1 then
print(‘passed4’)
jumpUsage -= 1
humanoid:ChangeState(Enum.HumanoidStateType.Jumping, true)
humanoid.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Landed then
jumpUsage = 1
end
end)
end
end
end
end)
Because it still doesn’t work
I was able to replicate the issue using both the emulator, and an actual Xbox controller, and it seems that the default jump action is overriding anything that tries to use ButtonA (oddly enough, it does register only once at the very beginning, but then that’s it)
I’ll try to see if using ContextActionService fixes the problem
no.. don’t use context action service for this. OR even detect inputs. As I’ve already said, UserInputService.JumpRequest exists and works the best method for this.
This code sample should work given I’ve written the variables the same as OP has, if it doesn’t work, I probably didn’t write one correctly, and the fix is just OP replacing it.
Okay so I added these prints to the script: uis.JumpRequest:Connect(function()
print(‘Jump requested’)
if humanoidRootPart and humanoid and humanoid:GetState() == Enum.HumanoidStateType.Freefall and jumpUsage > 0 then
print(‘Double jumping’)
jumpUsage -= 1
humanoid:ChangeState(Enum.HumanoidStateType.Jumping, true)
end
end) and double jump prints the exact same time as the first jump
I managed to get it working by using ContextActionService’s BindActionAtPriority so that the input is handled before the default script’s. I used a LocalScript in StarterCharacterScripts:
-- Tested using a LocalScript in StarterCharacterScripts
local ContextActionService = game:GetService("ContextActionService")
local JUMP_LIMIT = 2 -- If set to 2, the player's character can only jump twice
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid"):: Humanoid
local jumpUsage = 0
local function OnDoubleJump(_, userInputState: Enum.UserInputState): Enum.ContextActionResult
if userInputState == Enum.UserInputState.Begin and jumpUsage < JUMP_LIMIT then
jumpUsage += 1
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
return Enum.ContextActionResult.Sink
end
return Enum.ContextActionResult.Pass
end
local function OnStateChanged(_, newState: Enum.HumanoidStateType)
if newState == Enum.HumanoidStateType.Landed then
jumpUsage = 0
end
end
ContextActionService:BindActionAtPriority("DoubleJump", OnDoubleJump, false, 10000, Enum.KeyCode.Space, Enum.KeyCode.ButtonA)
humanoid.StateChanged:Connect(OnStateChanged)
Check Humanoid.FloorMaterial and make sure its Enum.Material.Air.
I wouldn’t personally recommend using CAS for this, its wayy overkill for what could be far simpler.