Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
Edited 7 years ago
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

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

The best thing I could think of is adding a number that adds up everytime the loop fires, and then you could add anIF 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)
Ad

Answer this question