sp=script.Parent framerate=30 frames=1 running=false direction=1 function waitForChild(A,J)while not A:FindFirstChild(J)do A.ChildAdded:wait()end end waitForChild(sp,"\066\111\116\116\111\109")waitForChild(sp.Bottom,"\079\112\101\110\068\111\111\114")waitForChild(sp.Bottom,"\067\111\110\102\105\103\117\114\097\116\105\111\110")function checkframes()if sp:FindFirstChild("\066\111\116\116\111\109")then local A=sp.Bottom:FindFirstChild("\067\111\110\102\105\103\117\114\097\116\105\111\110")if A then frames=math.floor(A.TimeToMove.Value*framerate)+1 end end end sp.Bottom.Configuration.TimeToMove.Changed:connect(checkframes)checkframes()function updatedoor(A)local J=A/frames if sp:FindFirstChild("\066\111\116\116\111\109")then local A=1.9 local X=sp.Bottom:FindFirstChild("\068\111\111\114\049")if X~=nil then X.C1=(CFrame.new(-A,-A,0)*CFrame.Angles(0,0,(math.pi/2)*J))*CFrame.new(A,A,0)end local o=sp.Bottom:FindFirstChild("\068\111\111\114\050")if o~=nil then o.C1=(CFrame.new(-A,A,0)*CFrame.Angles(0,0,(math.pi/2)*J))*CFrame.new(A,-A,0)end local l=sp.Bottom:FindFirstChild("\068\111\111\114\051")if l~=nil then l.C1=(CFrame.new(A,A,0)*CFrame.Angles(0,0,(math.pi/2)*J))*CFrame.new(-A,-A,0)end local P=sp.Bottom:FindFirstChild("\068\111\111\114\052")if P~=nil then P.C1=(CFrame.new(A,-A,0)*CFrame.Angles(0,0,(math.pi/2)*J))*CFrame.new(-A,A,0)end end end function runloop()if not running then running=true while true do if sp:FindFirstChild("\066\111\116\116\111\109")then local A=sp.Bottom:FindFirstChild("\070\114\097\109\101")if A then A.Value=A.Value+direction if A.Value>frames then A.Value=frames end if A.Value<=0 then A.Value=0 end updatedoor(A.Value)wait(1/framerate)if A then if A.Value<=0 and direction==-1 or A.Value>=frames and direction==1 then break end end else break end else break end end running=false end end function check(A)if A>.5 then direction=1 else direction=-1 end runloop()end sp.Bottom.OpenDoor.SourceValueChanged:connect(check)check(sp.Bottom.OpenDoor:GetCurrentValue())


sp=script.Parent
framerate=30

frames=1
running=false
direction=1


function waitForChild(instance,name)
	while not instance:FindFirstChild(name) do
		instance.ChildAdded:wait()
	end
end

waitForChild(sp,"Bottom")
waitForChild(sp.Bottom,"OpenDoor")
waitForChild(sp.Bottom,"Configuration")


function checkframes()
	if sp:FindFirstChild("Bottom") then
		local config=sp.Bottom:FindFirstChild("Configuration")
		if config then
			frames=math.floor(config.TimeToMove.Value*framerate)+1
		end
	end
end
sp.Bottom.Configuration.TimeToMove.Changed:connect(checkframes)
checkframes()


function updatedoor(frame)
	local percentage=frame/frames
	if sp:FindFirstChild("Bottom") then
		local hingedist=1.9
		local hinge1=sp.Bottom:FindFirstChild("Door1")
		if hinge1~=nil then
			hinge1.C1=CFrame.new(-hingedist,-hingedist,0)*CFrame.Angles(0,0,(math.pi/2)*percentage)*CFrame.new(hingedist,hingedist,0)
		end
		local hinge1=sp.Bottom:FindFirstChild("Door2")
		if hinge1~=nil then
			hinge1.C1=CFrame.new(-hingedist,hingedist,0)*CFrame.Angles(0,0,(math.pi/2)*percentage)*CFrame.new(hingedist,-hingedist,0)
		end
		local hinge1=sp.Bottom:FindFirstChild("Door3")
		if hinge1~=nil then
			hinge1.C1=CFrame.new(hingedist,hingedist,0)*CFrame.Angles(0,0,(math.pi/2)*percentage)*CFrame.new(-hingedist,-hingedist,0)
		end
		local hinge1=sp.Bottom:FindFirstChild("Door4")
		if hinge1~=nil then
			hinge1.C1=CFrame.new(hingedist,-hingedist,0)*CFrame.Angles(0,0,(math.pi/2)*percentage)*CFrame.new(-hingedist,hingedist,0)
		end
	end
end

function runloop()
	if not running then
		running=true
		while true do
			if sp:FindFirstChild("Bottom") then
				local frame=sp.Bottom:FindFirstChild("Frame")
				if frame then
					frame.Value=frame.Value+direction
					if frame.Value>frames then
						frame.Value=frames
					end
					if frame.Value<=0 then
						frame.Value=0
					end
					updatedoor(frame.Value)
					wait(1/framerate)
					if frame then
						if (frame.Value<=0 and direction==-1) or (frame.Value>=frames and direction==1) then
							break
						end
					end
				else
					break
				end
			else
				break
			end
		end
		running=false
	end
end

function check(val)
	if val>.5 then
		direction=1
	else
		direction=-1
	end
	runloop()
end

sp.Bottom.OpenDoor.SourceValueChanged:connect(check)
check(sp.Bottom.OpenDoor:GetCurrentValue())



