What do you want to achieve? Keep it simple and clear!
Double/triple jump system that uses InputBegan/Mouse1Click and humanoid:ChangeState(Enum.HumanoidStateType.Jumping, true) to listen and action jumps for mobile and PC.
What is the issue? Include screenshots / videos if possible!
I have a check in my script to only permit a double/triple jump to occur if humanoid is in Enum.HumanoidStateType.Freefall state but when jumping on PC via space bar the HumanoidStateType for humanoid results in ‘Running’ but on mobile pressing the jump button results in ‘Freefall’ (both tests conducted while character is standing still). This causes a problem as PC will allow for an extra jump and mobile will be at a disadvantage.
What solutions have you tried so far? Did you look for solutions on the Creator Hub?
I don’t want to go down the route of attempting to intercept jump requests nor use JumpRequest event as it feels unreliable to me - i’m hoping that understanding the reason behind this discrepancy will help me fix the logic.
local jumpUsage = 0
if rebirth.Value >= 1 and rebirth.Value < 5 then
jumpUsage = 1
elseif rebirth.Value >= 5 then
jumpUsage = 2
end
local mobileJumpButton = CheckForMobileJumpButton()
if mobileJumpButton then
mobileJumpButton.MouseButton1Click:Connect(function()
if humanoidRootPart and humanoid then
print(humanoid:GetState()) -- results in 'Freefall'
if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
print(humanoid:GetState()) -- results in 'Freefall'
if rebirth.Value >= 1 then
if jumpUsage >= 1 then
jumpUsage -= 1
humanoid:ChangeState(Enum.HumanoidStateType.Jumping, true)
print(jumpUsage)
end
end
humanoid.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Landed then
if rebirth.Value >= 1 and rebirth.Value < 5 then
jumpUsage = 1
elseif rebirth.Value >= 5 then
jumpUsage = 2
end
end
end)
end
end
end)
end
uis.InputBegan:Connect(function(key, gp)
if not gp then
if key.KeyCode == Enum.KeyCode.Space and key.UserInputType == Enum.UserInputType.Keyboard then
if humanoidRootPart and humanoid then
print(humanoid:GetState()) -- results in 'Running'
if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
print(humanoid:GetState()) -- doesn't get here until space bar is pressed a second time during Freefall state
if rebirth.Value >= 1 then
if jumpUsage >= 1 then
jumpUsage -= 1
humanoid:ChangeState(Enum.HumanoidStateType.Jumping, true)
print(jumpUsage)
end
end
humanoid.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Landed then
if rebirth.Value >= 1 and rebirth.Value < 5 then
jumpUsage = 1
elseif rebirth.Value >= 5 then
jumpUsage = 2
end
end
end)
end
end
end
end
end)
-- assume you want more rebirth requirements
-- highest rebirth requirement goes first
-- {RequiredRebirths, MaxAirJumps}
-- this is ugly in my opinion
local JUMP_TIERS = {
{5, 2}; -- 5+ rebirths = 2 air jumps
{1, 1}; -- 1+ rebirths = 1 air jump
}
local JumpUsage = 0
-- find the correct jump limit
local function GetMaxJumps()
for _, Tier in JUMP_TIERS do
local ReqRebirths, MaxJumps = Tier[1], Tier[2]
if Rebirth.Value < ReqRebirths then continue end
return MaxJumps
end
return 0
end
local function ResetJumps()
JumpUsage = GetMaxJumps()
end
local function PerformMultiJump()
if not (HumanoidRootPart and Humanoid) then return end
-- ignore inital jump
if Humanoid.FloorMaterial ~= Enum.Material.Air then
return
end
if Humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
return
end
if JumpUsage < 1 then return end
JumpUsage -= 1
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping, true)
print("Jumps left:", JumpUsage)
end
ResetJumps()
if Humanoid then
Humanoid.StateChanged:Connect(function(Old, New)
if New ~= Enum.HumanoidStateType.Landed then return end
ResetJumps()
end)
end
local MobileJumpButton = CheckForMobileJumpButton()
if MobileJumpButton then
MobileJumpButton.MouseButton1Click:Connect(PerformMultiJump)
end
Uis.InputBegan:Connect(function(Input, GameProcessed)
if GameProcessed then return end
if Input.UserInputType ~= Enum.UserInputType.Keyboard then return end
if Input.KeyCode ~= Enum.KeyCode.Space then return end
PerformMultiJump()
end)
have you actually read my reply? his .StateChanged which by the way wasn’t even the whole point of this topic is a ragebait to you? you are a total child overrreacting to everything
ah yes so funny bro, as I said, you are whining about a thing that was never part of the issue in the first place and assuming he is ragebaiting you on purpose
I’m not so smart in this case but I believe this stuff relates to delays in runtime
These give different outputs according to each waits:
if key.KeyCode == Enum.KeyCode.Space and key.UserInputType == Enum.UserInputType.Keyboard then
if humanoidRootPart and humanoid then
print(humanoid:GetState()) -- results in 'Running'
if humanoidRootPart and humanoid then
task.wait()
print(humanoid:GetState()) -- results in 'Jumping'
if humanoidRootPart and humanoid then
task.wait(0.1)
print(humanoid:GetState()) -- results in 'Freefall'