The debounce isn't working

Hello, this script is supposed to summon a pile of planks. I’d like the debounce to make the button available after 20 seconds but it doesn’t seem to work. The planks won’t be summoned again. Can anyone help me?

local planks = game.ReplicatedStorage.Planks
local position = game.Workspace.PlankPosisi
local debounce = false

function onTouched(click)
	
	if debounce == false then
		
		debounce = true
		local clone = planks:Clone()
		clone.Parent = workspace
		clone.Position = game.Workspace.PlankPosisi.Position
		wait(20)
		debounce = false
	end
end

script.Parent.ClickDetector.MouseClick:Connect(onTouched)
1 Like

I believe this is just an honest mistake, here:

local planks = game.ReplicatedStorage.Planks
local position = game.Workspace.PlankPosisi
local debounce = false

function onTouched(click)
	if debounce then return end
	debounce = true

	local clone = planks:Clone()
	clone.Parent = workspace
	clone.Position = game.Workspace.PlankPosisi.Position

	task.wait(20)

	debounce = false
end

script.Parent.ClickDetector.MouseClick:Connect(onTouched)
local storage = game:GetService("ReplicatedStorage")
local planks = storage:WaitForChild("Planks")
local position = workspace:WaitForChild("PlankPosisi")
local debounce = false

function onTouched(player)
	if debounce then
		return
	end
	debounce = true
	local clone = planks:Clone()
	clone.Parent = workspace
	clone.Position = position.Position
	task.wait(5)
	clone:Destroy()
	debounce = false
end

script.Parent.MouseClick:Connect(onTouched)

Server script, place it inside the “ClickDetector”, like this:

image

I have scripts in the planks, do they interfere with that?

It should not interfere with other things in the script.

Sorry but they haven’t worked so far.

Both of the provided scripts would work, you’re either placing them in the incorrect locations or have invalid references to other in-game instances.