Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Remote is firing even though value isn't 0?

So this is the clientside of my recent GUI, I want to make it fire a remote when the debounce value is 0, and when it isn't, not fire the remote and instead send a notification and a warning in console. Here is my code so you can get the idea of it.

batchbutton.MouseButton1Click:Connect(function()
print(batchdebounce)
if batchdebounce == 0 then --> This should stop the code below if the value isn't 0 and skip to line 16, but it doesn't
RippleEffect(batchbutton, m.X, m.Y)
warn('ADM --> Starting batch...') 
revent:FireServer(donutcode)
wait(2)
warn('ADM --> Batch successfully started.') 
SG:SetCore('SendNotification',  {
Title = 'Doughnut Machine';
Text = 'Batch successfully started.';
	})
	
	else
	
RippleEffect(batchbutton, m.X, m.Y)
warn('ADM --> You need to wait nil seconds to start a new batch!') 
SG:SetCore('SendNotification',  {
Title = 'Doughnut Machine';
Text = 'You need to wait nil seconds to start a new batch!';
})
end
end)

How can I make this work?

1 answer

local DEBOUNCE_LENGTH = 5

batchbutton.MouseButton1Click:Connect(function()
	print(batchdebounce)
	if batchdebounce == 0 then
		batchdebounce = 1
		RippleEffect(batchbutton, m.X, m.Y)
		warn('ADM --> Starting batch...') 
		revent:FireServer(donutcode)
		wait(2)
		warn('ADM --> Batch successfully started.') 
		SG:SetCore('SendNotification',  {
		Title = 'Doughnut Machine';
		Text = 'Batch successfully started.';
		    })
		wait(DEBOUNCE_LENGTH)
		batchdebounce = 0
	else
		RippleEffect(batchbutton, m.X, m.Y)
		warn('ADM --> You need to wait nil seconds to start a new batch!') 
		SG:SetCore('SendNotification',  {
		Title = 'Doughnut Machine';
		Text = 'You need to wait nil seconds to start a new batch!';
		})
	end
end)

I added a debounce and fixed your indenting.

This discussion is preserved as it was. New answers, comments, and votes are closed.