Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I add debounce to this short script?

Hey I was wondering how I'd add a debounce tot his short script, any help would be appreicated. :)

function onTouched(part)
	script.Parent.Parent.DoorScript.open.Value = true
	wait(3)
	script.Parent.Parent.DoorScript.open.Value = false
end


script.Parent.Touched:connect(onTouched)

2 answers

canopen = true -- the db

function onTouched(part)
	if canopen then
		canopen = false
		script.Parent.Parent.DoorScript.open.Value = true
		wait(2)
		script.Parent.Parent.DoorScript.open.Value = false
		canopen = true
	else
		print("Cannot open.")
	end
end


script.Parent.Touched:connect(onTouched)

Hope that helped. :)

4 comments

0

It just makes the time the door is closed for longer?

0

as I changed the wait time

0

wait just changes the time you need to wait before you can open again

0

this script works, I don't know why it was unmarked as the answer

local debounce = false

function onTouched(part)
if debounce = false then
	debounce = true
	script.Parent.Parent.DoorScript.open.Value = true
	wait(3)
	script.Parent.Parent.DoorScript.open.Value = false
	debounce = false
	end
end


script.Parent.Touched:connect(onTouched)

This discussion is preserved as it was. New answers, comments, and votes are closed.