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

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(0.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(0.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(0.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
