Debounce help with a door

Every time I think I understand where to put a debounce I do it wrong. Can someone show me where to put this debounce and explain why it goes in the spot you put it? I would greatly appreciate it.

Thanks

local TweenService = game:GetService("TweenService")
local door = script.Parent
local doorHinge = door.PrimaryPart
local doorOpen = TweenInfo.new()

local doorCFrame = TweenService:Create(doorHinge, doorOpen, {
	CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(-90),0)--Change 100 to whatever value. Range of swing.
})

local doorCFrameClosed = TweenService:Create(doorHinge, doorOpen, {
	CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(0),0)--Change 100 to whatever value. Range of swing.
})

local ProximityPrompt = script.Parent.ProximityPrompt
local PromptVanish = ProximityPrompt.Enabled == false
local PromptAppear = ProximityPrompt.Enabled == true

local debounce = false

ProximityPrompt.Triggered:Connect(function()
	debounce = true
	doorCFrame:Play()
	ProximityPrompt.Enabled = false
	script.Parent.Open:Play()--rbxassetid://192416578
	wait(3)--Door Stays Open this long
	doorCFrameClosed:Play()
	ProximityPrompt.Enabled = true
	script.Parent.Close:Play()
	debounce = false
end)

You should use conditionals for debounce to work.

add this

ProximityPrompt.Triggered:Connect(function()
if debounce == false then
	debounce = true
	doorCFrame:Play()
	ProximityPrompt.Enabled = false
	script.Parent.Open:Play()--rbxassetid://192416578
	wait(3)--Door Stays Open this long
	doorCFrameClosed:Play()
	ProximityPrompt.Enabled = true
	script.Parent.Close:Play()
	debounce = false
end
end)

Basically, everytime, before doing something, you check if a bool value (debounce) is false, only then do it. Once you start doing it, you immediately turn it to true, so that it wont get triggered anymore.
Once the action you were supposed to be doing is completely done, you turn it back to false, so that it can be triggered again.

You dont have to call it debounce, you can call it whatever you want, as long as it is a bool value, it is just the common way to call it debounce

As @Darkwulf7777 and @TheDestroyer0525 said, you need to check if the debounce is true or false .
here’s some good info from the developer.roblox.com site Debounce – When and Why

1 Like