Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to disable the space bar temporarily after jumping?

Asked by 4 years ago

I want to add a denounce to the space bar when the player jumps, and disable it temporarily. The problem is, I don't know how to do this. Here is my failed attempt.

01local character = script.Parent
02 
03local JUMP_DEBOUNCE = 5
04 
05local humanoid = character:WaitForChild("Humanoid")
06 
07local isJumping = false
08humanoid.StateChanged:Connect(function(oldState, newState)
09    if newState == Enum.HumanoidStateType.Jumping then
10        if not isJumping then
11            isJumping = true
12            humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping and Enum.KeyCode.Space, false)
13        end
14    elseif newState == Enum.HumanoidStateType.Landed then
15        if isJumping then
View all 21 lines...

1 answer

Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago
01-- Variables --
02local character = script.Parent
03local humanoid = character:WaitForChild("Humanoid")
04local isJumping = false
05local UserInputService = game:GetService("UserInputService")
06local DisablingJumpingTime = 5
07 
08-- Script --
09 
10humanoid.StateChanged:Connect(function(oldState, newState)
11    if newState == Enum.HumanoidStateType.Jumping then
12        if not isJumping then
13            isJumping = true
14            wait() -- dont know why, but this wait() fixes it
15            humanoid.JumpPower = 0 -- Instead of disabling the jumping, you can change the JumpPower to 0 instead!
View all 24 lines...
0
This way is more straightforward and easier. If this helped you, please consider marking this an answer so people will know! Xapelize 2658 — 4y
0
If this didn't work, try putting this on StarterPlayer > StarterCharacterScripts and putting this as an LocalScript. Thanks for reading! Xapelize 2658 — 4y
0
I appreciate your help but how can this be done with the space bar? SilverishReign 75 — 4y
0
Oh, you actually can, just replace the humanoid.JumpPower = 0 to humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping and Enum.KeyCode.Space, false). I am not really sure since I do not understand a lot of HumanoidStateType. So humanoid jump power is the best way for me! Xapelize 2658 — 4y
Ad

Answer this question