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

[Solved] JumpRequest triggering too many times?

Asked by 4 years ago
Edited 4 years ago

Hello,

I am working on a script that makes you fly when you double press jump. When a player on the computer double jumps, it works perfectly. However, when a mobile player double jumps with their special jump button, they only need to jump once to start flying (but twice to stop flying??). I think the reason this does not work is because JumpRequest gets triggered multiple times during a jump but I am not sure how to fix this.

Here is the part for mobile players that I am struggling with:

function JumpRequest()
    if uis.TouchEnabled and not uis.KeyboardEnabled and not uis.MouseEnabled then
        if not Tapped then
            Tapped = true
            wait(TapTime)
            Tapped = false
        else
            if not flying then
                fly()
            else
                endFlying()
            end
        end
    end
end

uis.JumpRequest:Connect(JumpRequest)

And this is how I do it for computer players:

uis.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.Space then
        if not Tapped then
            Tapped = true
            wait(TapTime)
            Tapped = false
        else
            if not flying then
                fly()
            else
                endFlying()
            end
        end
    end
end)

By the way, if there is a way to merge both of these together, I am open to suggestions!

Thanks for your help and time!

2 answers

Log in to vote
1
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago

First, you can easily reduce it so 21 lines instead of 32, and also, just add debounce.

More information: https://developer.roblox.com/en-us/api-reference/event/UserInputService/JumpRequest

https://developer.roblox.com/en-us/articles/Debounce

local userInputService = game:GetService("UserInputService")
local debounce = false
function jumpRequest()
    if debounce == false then
        debounce = true
        if not Tapped then
            Tapped = true
            wait(TapTime)
            Tapped = false
        else
            if not flying then
                fly()
            else
                endFlying()
            end
        end
        wait(3)
        debounce = false
    end
end

userInputService.JumpRequest:Connect(JumpRequest)
Ad
Log in to vote
0
Answered by 4 years ago

Solved It!

local debounce = false
function JumpRequest()
    if not debounce then
        debounce = true
        wait(0.01)
        debounce = false
        if not Tapped then
            Tapped = true
            wait(TapTime)
            Tapped = false
        else
            if not flying then
                fly()
            else
                endFlying()
            end
        end
    end
end

uis.JumpRequest:Connect(JumpRequest)

Thank you for your help!

Answer this question