repeat(game:GetService("\082\117\110\083\101\114\118\105\099\101")).Stepped:Wait()until game.Players.LocalPlayer local Z=script.Parent.Parent local x=Z:GetMouse()local s=false local F x.Button1Up:Connect(function()if s==true then F=x.Target if F.Using.Value==false and(F.Parent==workspace.Valves and script.Parent.IsUsingValve.Value==false)then if box then box:Destroy()end F.Using.Value=true script.Parent.IsUsingValve.Value=true local Z=workspace.CurrentCamera local x=game:GetService("\084\119\101\101\110\083\101\114\118\105\099\101")local s=Z.CFrame repeat wait(.01)Z.CameraType=Enum.CameraType.Scriptable until Z.CameraType==Enum.CameraType.Scriptable character.HumanoidRootPart.Anchored=true script.Parent.ValveUI.Enabled=true;(x:Create(Z,TweenInfo.new(1,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out),{CFrame=F.offset.WorldCFrame})):Play()repeat wait(.01)until F.Orientation.X>59 wait(1.5)script.Parent.ValveUI.Enabled=false F.Turn:Play()F.Parent=workspace.Valves.Completed F.Using.Value=false wait(.3);(x:Create(Z,TweenInfo.new(1,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out),{CFrame=s})):Play()F=nil wait(1)script.Parent.IsUsingValve.Value=false character.HumanoidRootPart.Anchored=false repeat wait(.01)Z.CameraType=Enum.CameraType.Custom until Z.CameraType==Enum.CameraType.Custom end end end)x.KeyDown:Connect(function(Z)if Z=="\100"then holding=true print("\112\108\097\121")e="\070\114\111\110\116"end end)x.KeyUp:Connect(function(Z)if Z=="\100"then holding=false e="\110\105\108"print("\115\116\111\112")elseif Z=="\097"then holding=false e="\110\105\108"print("\115\116\111\112")end end)while wait()do for Z,x in pairs(workspace.Valves.Completed:GetChildren())do if Z==5 then workspace.Door.Open:FireServer()end end if F and holding==true then if e=="\070\114\111\110\116"then print("\081")F.CFrame=F.CFrame*CFrame.fromEulerAnglesXYZ(.09,0,0)elseif e=="\066\097\099\107"then print("\069")F.CFrame=F.CFrame*CFrame.fromEulerAnglesXYZ(-0.05,0,0)end end if x.Target then if script.Parent.IsUsingValve.Value==false and x.Target.Name=="\049"or x.Target.Name=="\050"or x.Target.Name=="\051"or x.Target.Name=="\052"or x.Target.Name=="\053"or x.Target.Name=="\054"then if not x.Target:FindFirstChild("\115\101\108\101\099\116\105\111\110")and(x.Target.Parent==workspace.Valves and(x.Target.Using.Value==false and script.Parent.IsUsingValve.Value==false))then box=script.Parent.ValveUI.selection:clone()box.Parent=x.Target s=true box.Adornee=x.Target end else s=false if box then box:Destroy()end end end end


repeat game:GetService("RunService").Stepped:Wait() until game.Players.LocalPlayer
local player = script.Parent.Parent
local mouse = player:GetMouse()
local selecting = false
local valve

mouse.Button1Up:Connect(function()
	if selecting == true then
		 valve = mouse.Target
		if valve.Using.Value == false and valve.Parent == workspace.Valves and script.Parent.IsUsingValve.Value == false then
			if box then
				box:Destroy()
			end
			valve.Using.Value = true
			script.Parent.IsUsingValve.Value = true
			local camera = workspace.CurrentCamera
			local tweenservice = game:GetService('TweenService')
			local cf = camera.CFrame
			repeat
				wait(.01)
				camera.CameraType = Enum.CameraType.Scriptable
			until camera.CameraType == Enum.CameraType.Scriptable
			character.HumanoidRootPart.Anchored = true
			script.Parent.ValveUI.Enabled = true
			tweenservice:Create(camera,TweenInfo.new(1,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out), {CFrame = valve.offset.WorldCFrame}):Play()
			repeat
				wait(.01)
			until valve.Orientation.X > 59
			wait(1.5)
			script.Parent.ValveUI.Enabled = false
			valve.Turn:Play()
			valve.Parent = workspace.Valves.Completed
			valve.Using.Value = false
			wait(0.3)
			tweenservice:Create(camera,TweenInfo.new(1,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out), {CFrame = cf}):Play()
			valve = nil
			wait(1)
			script.Parent.IsUsingValve.Value = false
			character.HumanoidRootPart.Anchored = false
			repeat
				wait(.01)
				camera.CameraType = Enum.CameraType.Custom
			until camera.CameraType == Enum.CameraType.Custom

		end
	end
end)

mouse.KeyDown:Connect(function(key)
	if key == "d" then
		holding = true
		print('play')
		e = 'Front'
		end
end)

mouse.KeyUp:Connect(function(key)
	if key == "d" then
		holding = false
		e = 'nil'
		print('stop')
		
	elseif key == "a" then
		holding = false
		e = 'nil'
		print('stop')

	end
end)

while wait() do	
	
	for i,v in pairs(workspace.Valves.Completed:GetChildren()) do
		if i == 5 then
			workspace.Door.Open:FireServer()
		end
	end
	if valve and holding == true then
		if e == 'Front' then
			print('Q')
			valve.CFrame = valve.CFrame * CFrame.fromEulerAnglesXYZ(0.090,0,0)

		elseif e == 'Back' then
			print('E')
			valve.CFrame = valve.CFrame * CFrame.fromEulerAnglesXYZ(-0.050,0,0)


		end
	end
	
	if mouse.Target then
		if script.Parent.IsUsingValve.Value == false and mouse.Target.Name == '1' or mouse.Target.Name == '2' or mouse.Target.Name == '3' or mouse.Target.Name == '4' or mouse.Target.Name == '5' or mouse.Target.Name == '6' then
				if not mouse.Target:FindFirstChild('selection') and mouse.Target.Parent == workspace.Valves and mouse.Target.Using.Value == false and script.Parent.IsUsingValve.Value == false then
					box = script.Parent.ValveUI.selection:clone()
				box.Parent = mouse.Target
				
					selecting = true
					box.Adornee = mouse.Target
				end
		else
				selecting = false
				if box then
					box:Destroy()
				end
			end
		
	end	
end

