local key = script.Parent
local dataLink = script["Data Link"].Value

function rotateMod(mod, center, rotation)
	local parts = {}
	local function scan(parent)
		for _, obj in pairs(parent:GetChildren()) do
			if (obj:IsA("BasePart")) then
				table.insert(parts, obj)
			end
			scan(obj)
		end
	end

	scan(mod)
	for _, part in pairs(parts) do
		part.CFrame = (center * rotation * (center:inverse() * part.CFrame))
	end
end

function onClicked()

	if dataLink.temporalLocatorActive.Value == false then
		dataLink.temporalLocatorActive.Value = true
		script.Parent.Parent.Hinge.Part.Color = Color3.fromRGB(0, 255, 0)
		script.Parent.Main.Sound:Play()
		script.Parent.Main.beep:Play()
		local mod = key
		local step = 1
		for i = 0, 4.5, step do
			rotateMod(mod, mod:GetModelCFrame(), CFrame.Angles(0, -0.3, 0))
			wait()
		end
	else
		dataLink.temporalLocatorActive.Value = false
		script.Parent.Parent.Hinge.Part.Color = Color3.fromRGB(255, 0, 0)
		script.Parent.Main.Sound:Play()
		local mod = key
		local step = 1
		for i = 0, 4.5, step do
			rotateMod(mod, mod:GetModelCFrame(), CFrame.Angles(0, 0.3, 0))
			wait()
		end
	end
end

script.Parent.Main.Use.MouseClick:connect(onClicked)


