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

Clicking again to close the door?

Asked by 7 years ago

So I have made a door with this script. So when I click on it the door swings open. Tho I want it to make it so when door is open and I click on it will close again to the same postion, how could I do this?

local Door = script.Parent.Parent
local Main = Door.Main
local Button = script.Parent

local Opened = false
Button.ClickDetector.MouseClick:connect(function()
    if Opened == false then
        Opened = true
        for i = 0,3,.1 do
        Door:SetPrimaryPartCFrame(Door:GetPrimaryPartCFrame() *         CFrame.Angles(0,math.rad(math.pi/1),0))
            wait()
        end
    end
end)

0
Else statement? Starhawke_r 11 — 7y
0
Not sure how i'm gonna use that in there ItsRickGrimes 20 — 7y

1 answer

Log in to vote
0
Answered by
deris88 146
7 years ago

Hi.

In this case you should use else statement. It is is simple to use:

local Open = false

function Door()
    if Open = false then        
        Open = true
        for i=0, 3 do
            Door:SetPrimaryPartCFrame(Door:GetPrimaryPartCFrame() *         CFrame.Angles(0,math.rad(math.pi/1),0))
            wait(0.1)
        end
    else                  --If Open is not false then it will do the following:
        for i=0, 3 do
            Door:SetPrimaryPartCFrame(Door:GetPrimaryPartCFrame() *         CFrame.Angles(0,-math.rad(math.pi/1),0)--We will be using negative math.rad() in order to close
            wait(0.1)
        end
        Open = false                --When it is closed, we must tell the script that it is
    end
end

Button.ClickDetector.MouseClick:connect(Door)

Hope this helps.

0
Thanks for the help, I found another way I might use tho :) ItsRickGrimes 20 — 7y
Ad

Answer this question