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

Clicking again to close the door?

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)

2 comments

0

Else statement?

0

Not sure how i'm gonna use that in there

1 answer

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.

1 comment

0

Thanks for the help, I found another way I might use tho :)

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