Need help door to auto closing when idle for 5 seconds

Hi guys, I need you guys to help me add more a bit parts to the script to make it will be auto-closing when the door idles 5 seconds after pushing on Proximity Promt and it started opening.
It just closes when someone clicks on it, but I want it can auto-closing when no one not pushing on that button once again to close it
Here is my script, please help add more things to make this door auto-closing when no one pushing on it one again

local isopen = script.Parent.IsOpen
local idle = true
local button1 = script.Parent.Button1
local button2 = script.Parent.Button2
local click1 = button1.ProximityPrompt
local click2 = button2.ProximityPrompt
function active(silent)
	if idle and not script.Parent.Locked.Value then
		idle = false
		local count = 0.065
		if not isopen.Value then
			script.Parent.Door1.CanCollide = false
			script.Parent.Door2.CanCollide = true
			if not silent then
				script.Parent.Main["Open" .. math.random(1,3)]:Play()
			end
			for i=1,35 do
				wait()
				script.Parent.Door1.CFrame = script.Parent.Door1.CFrame * CFrame.new(count,0,0)
				script.Parent.Door2.CFrame = script.Parent.Door2.CFrame * CFrame.new(count,0,0)
				if i < 18 then
					count = count * 1.05
				else
					count = count / 1.05
				end
			end
			isopen.Value = true
		else
			script.Parent.Door1.CanCollide = false
			script.Parent.Door2.CanCollide = true
			if not silent then
				script.Parent.Main["Close" .. math.random(1,3)]:Play()
			end
			for i=1,35 do
				wait()
				script.Parent.Door1.CFrame = script.Parent.Door1.CFrame * CFrame.new(-count,0,0)
				script.Parent.Door2.CFrame = script.Parent.Door2.CFrame * CFrame.new(-count,0,0)
				if i < 18 then
					count = count * 1.05
				else
					count = count / 1.05
				end
			end
			isopen.Value = false
		end
		wait(0.2)
		idle = true
	end
end

button1.ProximityPrompt.Triggered:connect(function()
	button1.Push:Play()
	active()
end)
button2.ProximityPrompt.Triggered:connect(function()
	button2.Push:Play()
	active()
end)
button1.Pushed.Changed:connect(function()
	if button1.Pushed.Value then
		button1.Pushed.Value = false
		button1.Push:Play()
		active()
	end
end)
button2.Pushed.Changed:connect(function()
	if button2.Pushed.Value then
		button2.Pushed.Value = false
		button2.Push:Play()
		active()
	end
end)

1 Like