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

How do I make the door close after it's been opened?

Asked by 10 years ago

I'm trying to make a clickable door, and I've made it so it's rotated open with this script:

game.Workspace.Door.Script.Name = "Clickable Door Script"
script.Parent.ClickDetector.MouseClick:connect(function()
game.Workspace.Door.Rotation = Vector3.new(0,3,0)
end)

I want to make it able to close if you click it again.

1 answer

Log in to vote
1
Answered by
Aethex 256 Moderation Voter
10 years ago

You would use a simple variable to check if it has been opened or not.

local open = false;

script.Name = "Clickable Door Script"; -- On the assumption that this is that script

script.Parent.ClickDetector.MouseClick:connect(function()

    if not open then -- Checks if closed

        script.Parent.Rotation = Vector3.new(0, 3, 0);

        open = true;

    else -- If open

        script.Parent.Rotation = Vector3.new(0, 0, 0);

        open = false;

    end

end)
0
Thank you! AudreyJeanx 55 — 10y
0
Wait, it's still not working? AudreyJeanx 55 — 10y
0
Is the script inside of the part? Aethex 256 — 10y
0
I edited it. It wouldn't work if there was more than one door before. Aethex 256 — 10y
View all comments (3 more)
0
There isn't. I'm only working on one AudreyJeanx 55 — 10y
0
And, yes, the script is inside of the part. AudreyJeanx 55 — 10y
0
Thank you! :) AudreyJeanx 55 — 10y
Ad

Answer this question