Debounce script would not work

My debounce script seems to malfunction and it keeps printing the first argument, I don’t know how I could fix that if anyone has answer I’d be very grateful, thank you.

I haven’t touched lua in some time so I’m kind of in-experienced at the moment sorry for that.

GUIs.Button.MouseButton1Click:Connect(function()
		local RemoteEvent = Seat:FindFirstChild("RemoteEvent") :: RemoteEvent
		
		if not SeatInclination then
			RemoteEvent:FireServer("Decline")
			task.wait(1)
			SeatInclination = true			
			
		else
			RemoteEvent:FireServer("Incline")
			task.wait(1)
			SeatInclination = false
		end
	end)

Here’s the general format for a debounce like this:

local WAIT_TIME = 1
local debounce = false

GUIs.Button.MouseButton1Click:Connect(function()
	if debounce then
		return
	end

	debounce = true 

	-- add your code here

	task.wait(WAIT_TIME)
	debounce = false
end)

what about the 2nd parameter? do I add it in the same place as the 1st one?

What second parameter?

if not SeatInclination then
			RemoteEvent:FireServer("Decline")
			task.wait(1)
			SeatInclination = true			
			
		else
			RemoteEvent:FireServer("Incline")
			task.wait(1)
			SeatInclination = false
		end

RemoteEvent:FireServer(“Incline”)

This should work

local remoteEvent = Seat:FindFirstChild("RemoteEvent") :: RemoteEvent

local WAIT_TIME = 1

local debounce = false
local inclined = false

GUIs.Button.MouseButton1Click:Connect(function()
	if debounce then
		return
	end

	debounce = true 

	remoteEvent:FireServer(inclined and "Decline" or "Incline")
	inclined = not inclined

	task.wait(WAIT_TIME)
	debounce = false
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.