Double Jump Fire Server

So essentially I need jump to be equal to 0 after a .8 secs because I can jump, jump will be one, wait as long as I want and jump again and it will fire the event.
I have tried a few thing and result in it printing one jump multiple times even though I click it within the time limit.

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local pressedtime = tick()
decounce = true
jump = 0
UIS.JumpRequest:Connect(function()
    
if decounce then 
    decounce = false
    jump = jump + 1
    print(jump)
    pressedtime = tick()
    
    
    if tick() - pressedtime <= .8 and jump == 2 then 
        jump = 0
    game.ReplicatedStorage.StopFly:FireServer()
    wait(.5)
    script.Disabled = true
    script.Parent.Fly.Disabled = false
   
       end
    wait(.1)
    decounce = true
    
   end         
end)
1 Like

Can you please elaborate on your question? I don’t quite understand. Maybe it’s just me, sorry.

1 Like

Yeah my apologies its kind of hard to understand. So essentially I jump to reset to 0 if it is not pressed in a certain amount of time , hopefully that makes more sense, if not let me know!

First of all, “decounce” :nauseated_face:

Your time limit isn’t working because you’re resetting the lower bound every single time. What I mean by that is, every time this function runs you’re resetting ‘pressedtime’ to tick() and then immediately checking to see if the difference is less than 0.8 seconds, which it pretty much always will be (unless you’re on a dinosaur computer).

What you need to do is save the time from the last press and then check it in the following function call.
Something like:

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local pressedtime = 0
decounce = true
jump = 0

UIS.JumpRequest:Connect(function()
    if decounce then 
        decounce = false
        jump = jump + 1
        print(jump)

        if tick() - pressedtime <= 0.8 and jump == 2 then 
            jump = 0
            pressedtime = 0
            game.ReplicatedStorage.StopFly:FireServer()
            wait(0.5)
            --script.Disabled = true  -- Why would you want to turn the script off while it's still running?
            script.Parent.Fly.Disabled = false
        elseif jump == 1 then
            pressedtime = tick()
        end
        decounce = true
   end         
end)
2 Likes