I don't get why debounce is not working

I tried to make a button. It in fact works, but when pressed with an autoclicker, it sinks.
I expect people to break the button with autoclicker, and I have searched how to make debounce correctly, but it still won’t work.
I’m sorry if it’s caused by my stupidity.

Here I’m pressing it pretty fast with my finger, and then with autoclicker.

https://gyazo.com/092a36796fb0eb7631b871b4e4b769d7

local part = script.Parent
local counter = game.Workspace:WaitForChild("Counter")
local countGui = counter.SurfaceGui
local text = countGui.TextLabel
local click = Instance.new("ClickDetector", part)
local n = 0
local db = false


click.MouseClick:Connect(function()
	if db == true then return end
	db = true
	n = n + 1
	text.Text = ( n .. " points")
	local TweenService = game:GetService("TweenService")
	local goal = {}
	goal.Position = part.Position + Vector3.new(0, -0.1, 0)
	
	local tweenInfo = TweenInfo.new(0.05, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, true, 0)
	
	local tween = TweenService:Create(part, tweenInfo, goal)
	
	tween:Play()
	db = false	
end)

You should wait for the tween to finish before setting debounce to true again.

tween:Play()
tween.Completed:Wait()
2 Likes

I completely forgot to do it, since I believed that :Play meant it would automatically wait for it to end.
Thank you.