Debounce not working

Hello!
My script won’t run through the debounce and I don’t what’s wrong. Please Help!

script

local function Touched(part)
	local db = false
	if not db then return end
	local player = game:GetService("Players"):GetPlayerFromCharacter(part.Parent)
	db = true
	--Main function--
	game.ReplicatedStorage.FactoryPlot.Parent = player.PlayerGui
	local ui = player.PlayerGui.FactoryPlot.Frame
	ui:TweenPosition(
		UDim2.new(.5, 0, 0.5, 0), "Out", "Quad", 1, false
	)
	wait(3)
	db = false
end

nvm im stupid ur right i did not read that part(Lol i read it too fast so i did not realize it was there)

Define the debounce outside of the function
The point of the debounce is for it to be synonymous across calls

2 Likes

I like putting the debounce in a function so I can make other debounces.

Thats not good it can mess up ur scripts somtime

1 Like

wait nvm, in this script im always setting debounce to false

Ye just say

local touchedDebounce = false

Theres no way for it to work otherwise

oh i was right lol XD good liuck

Oh yeah, and I got the if statement wrong :frowning: