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

How would I make it so after 1 second of not clicking the combo resets?

Asked by 3 years ago

I want to make it so when you stop clicking for 1 second (or more) it resets the combo

mouse.Button1Down:connect(function()
    if cooldown == true then return end
        if combo == 0 then
        cooldown = true
            combo = 1
            print("first m1")
            m1:Play()
            wait(.3)
            game.ReplicatedStorage.Dmg:FireServer(leftarm,5,.8)
            wait(.47)
        cooldown = false
    elseif combo == 1 then
        cooldown = true
        combo = 2
        print("second m1")
        m2:Play()
        wait(.1)
        game.ReplicatedStorage.Dmg:FireServer(rightarm,5,.3)
        wait(.19)
        cooldown = false
    elseif combo == 2 then
        cooldown = true
        combo = 3
        print("third m1")
        m3:Play()
        wait(.1)
        game.ReplicatedStorage.Dmg:FireServer(leftarm,5,.3)
        wait(.19)
        cooldown = false
    elseif combo == 3 then
        cooldown = true
        combo = 0
        print("fourth m1")
        m4:Play()
        wait(.2)
        game.ReplicatedStorage.Dmg:FireServer(leftleg,8,.3)
        wait(1.5)
        cooldown = false
    end
end)

1 answer

Log in to vote
1
Answered by 3 years ago

Add a while true loop running in a different thread so as not to yield the current thread in case you want code Fter that. Inside this while true do loop, check every second to see if the value was the same as last time, if it is, then that means nothing was added to the combo meaning it should end.

Example of running code in another thread, basically running multiple code at once:

Spawn(function()

     --code

end)

So to do all of this would be something like:

Spawn(function()

     lastCombo = 0 

     While true do

          wait(1) --always wait 1 second

          If combo == lastcombo then -- checks if combo was same as it was a second ago

               combo = 0 -- cancels/resets combo if it was the same meaning the combo hasn't increased

          end

          lastCombo = combo -- setting the last combo then restarting loop which waits a second before executing the check again.

     end

end)

Hope this helps:3

1
It works perfectly! Thank you, I will make sure to note this in my head so I don't have to ask for help in the future, cheers. bluewell101 8 — 3y
0
No problem, keep asking questions AlexanderYar 788 — 3y
0
I don't suggest using spawns various reasons, use corountines instead. JesseSong 3916 — 3y
Ad

Answer this question