How would I go about adding a delay to this Clickdetector event

Currently trying to make a Rust Tool Cupboard System. I haven’t mess with LUA in a while. I’m trying to add so it has a wait instead of doing the video below. I click it once and it Removes and also adds the user and vice versa. Would I go about possibly doing a Bool?

TC = script.Parent.ToolCupboard
Auth_Deauth_Detect = TC.Auth_Deauth
isLocked = script.Parent.IsLocked
isOpen = script.Parent.IsOpen

local AuthTable = { "R3DActual" }

function onAuthDeauth()
	Auth_Deauth_Detect.MouseClick:Connect(function(plr)
		if(table.find(AuthTable, plr.Name)) then
			print("Removed from Tool Cupboard")
			table.remove(AuthTable, table.find(AuthTable, plr.Name))
		else
			if(isLocked.Value == true) then
				print("Tool Cupboard is locked")
			else
				print("Added to Tool Cupboard")
				table.insert(AuthTable, plr.Name)
			end
		end
	end)
end

Auth_Deauth_Detect.MouseClick:connect(onAuthDeauth)
1 Like

task.delay(time,function()end)

1 Like

Decided to do this instead and it works great!

TC = script.Parent.ToolCupboard
Auth_Deauth_Detect = TC.Auth_Deauth
isLocked = script.Parent.IsLocked
isOpen = script.Parent.IsOpen

local AuthTable = { "R3DActual" }

canDeauth = true

function onAuthDeauth()
	Auth_Deauth_Detect.MouseClick:Connect(function(plr)
		if(canDeauth == true) then
			canDeauth = false
			if(table.find(AuthTable, plr.Name)) then
				print("Removed from Tool Cupboard")
				table.remove(AuthTable, table.find(AuthTable, plr.Name))
				wait(0.8)
				canDeauth = true
			else
				if(isLocked.Value == true) then
					print("Tool Cupboard is locked")
				else
					print("Added to Tool Cupboard")
					table.insert(AuthTable, plr.Name)
					wait(0.8)
					canDeauth = true
				end
			end
		end
	end)
end

Auth_Deauth_Detect.MouseClick:connect(onAuthDeauth)

Wait() has been deprecated use task.wait instead. There is a reason it’s been deprecated and you should update it.