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

How do I make sure the loop isn't duplicated when MouseButton1 is being held?

Asked by 4 years ago

Hello, I am basically trying to make a system so if you hold something for a certain amount of seconds, it awards you something. But you can also hold onto it so you can keep getting it without re clicking.

The code for what I'm trying to achieve is below:

while hold == true do
    wait(WaitTime)
    if hold == true then
        sendEvent(part)
    else
        break
    end
end

I'm basically using rays to detect the click of a part, and InputEnded to make hold = false, but I found an issue that if you re-click it within the WaitTime seconds, everything will be duplicated and it will run again, because when you click it again, the InputBegan event is firing again.

If anyone knows how I can fix this, please let me know!

0
deb LinavolicaDev 570 — 4y
0
I mean the deb for the status LinavolicaDev 570 — 4y
0
I basically need a way to check if hold is == true at the exact same time and length of the wait() incase the user clicks off and on, but I don't really know how I can achieve this. Jack_AviationRBX 25 — 4y
1
use a debounce variable that surrounds the while loop Code1400 75 — 4y
0
Ah thanks, got it working now. Jack_AviationRBX 25 — 4y

Answer this question