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!

5 comments

0

deb

0

I mean the deb for the status

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.

1

use a debounce variable that surrounds the while loop

0

Ah thanks, got it working now.