I have a script that puts a jump cooldown/disables being able to hold the jump button. This works fine on PC but I’ve run into a problem where the mobile jump button disappears once the Humanoid.JumpPower = 0, and doesn’t come back once its back at its regular value.
canjump = 10
runservice.RenderStepped:Connect(function()
canjump = math.clamp(canjump-1,0,10))
end)
local uis = game:GetService("UserInputService")
humanoid.UseJumpPower = true
uis.JumpRequest:Connect(function()
if canjump == 0 then
humanoid.JumpPower = 40
else
humanoid.JumpPower = 0
end
canjump = 10
end)
One fix could be to assign an infinitesimal to the ‘JumpPower’ property, i.e; 0.0001 (or lower if necessary). The other option would be to fork the mobile jump button itself.
Setting your jump power or jump height to zero removes the jump button, and comes back once it changes. In the code, jumping sets your JumpPower to zero but never sets it back to 40. You can only set the JumpPower back to 40 if the player attempts to jump, but since you can’t actually attempt a jump (due to the button not visible), it’s impossible.
That’s bad practice, if you want to do it the right way then play test in studio on a mobile device.
Go to game.Players.LocalPlayer.PlayerScriptsin your explorer and copy the PlayerModule that is there, then end the play test and paste the player module in StarterPlayer > StarterPlayerScripts.
in PlayerModule.ControlModule.TouchJump module there is a connection that connects whenever the humanoid’s JumpPower property changes, and if its 0 then the JumpButton becomes invisible, simply delete the connection code and the button will stop dissapearing.
Hope that this helps, it’s actually very easy to do!
I know this is an old thread, but since it was bumped back up to the top of the forum, I figured I would provide some insight for anyone who reads through this thread in the future.
For anyone with the same / a similar question to this, note that setting Humanoid.JumpPower to 0 is not the recommended way of achieving a jump cooldown / disabling the ability to jump, as mentioned on its Roblox Creator Documentation page:
Recently, I came up with a solution that doesn’t require forking any of the default PlayerScripts, utilizes Humanoid:SetStateEnabled(), is compatible with multiple input types (including touch-screens), and solves the issue brought up in the original post of this thread of the jump button not re-appearing.
The post below includes complete LocalScript code for achieving that with a full explanation of how the code works: