--AdmiralLennox

Chest = script.Parent
Lid = Chest.Lid
Lid.PrimaryPart = Lid.Hinge

increment = 96
debounce = false

function rotate(model, amount)
		for i=1, math.abs(amount/2) do
			model:SetPrimaryPartCFrame(model.Hinge.CFrame * CFrame.fromEulerAnglesXYZ(0,math.pi/amount,0))
			wait()
		end	
end

function openChest()
	print("Clicked on handle.")
	
	if not debounce then
		debounce = true
		if Chest.Open.Value then
			rotate(Lid, increment)
		else
			rotate(Lid, -increment)
		end
		Chest.Open.Value = not Chest.Open.Value
		debounce = false
	else
	end
end

Lid.ClickDetector.MouseClick:Connect(openChest)
