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

How can I make my doors close automatically after a certain amount of time?

Button = script.Parent.Button.ClickDetector
SecondButton = script.Parent.ButtonTwo.ClickDetector

---Door Parts---
WOne = script.Parent.WedgeOne
WTwo = script.Parent.WedgeTwo

---Positions---
WPOne = script.Parent.PosOne
WPTWo = script.Parent.PosTwo


Button.MouseClick:connect(function()
	for i = 0,1,0.01 do
		WOne.CFrame = WOne.CFrame:lerp(WPOne.CFrame, i)
		WTwo.CFrame = WTwo.CFrame:lerp(WPTWo.CFrame, i)
		wait()
	end
end)


SecondButton.MouseClick:connect(function()
	for i = 0,1,0.01 do
		WOne.CFrame = WOne.CFrame:lerp(WPOne.CFrame, i)
		WTwo.CFrame = WTwo.CFrame:lerp(WPTWo.CFrame, i)
		wait()
	end
end)

So I made doors that open with the lerp() method but I cant figure out how to close them automatically after a certain amount of time.

The wait at the end of each for loop is necessary to make the transition smooth, and I am out of ideas any and all help is appreciated.

1 answer

✓ Accepted answer

The best thing I could think of is adding a number that adds up everytime the loop fires, and then you could add an IF THEN statement to check if its closed, and if it is you could add a wait time for it to close.

EG.

local CheckingTimes = 0
Button.MouseClick:connect(function()
      for i = 0,1,0.01 do
	if CheckingTimes <= 20 then
			 WOne.CFrame = WOne.CFrame:lerp(WPOne.CFrame, i)
        		WTwo.CFrame = WTwo.CFrame:lerp(WPTWo.CFrame, i)
			CheckingTimes = CheckingTimes + 1
			wait()
		elseif CheckingTimes > 20 then
			wait(time to wait)
			(script to close door)
	end
    end
end)

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