local C=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local J=require(C.Shared.components)local E=require(C.Lib.Matter)local function l(l)if E.useThrottle(10)then local C=Vector3.new(500,500,500)*Vector3.new(math.random(1,2)==1 and 1 or-1,1,math.random(1,2)==1 and 1 or-1)local E=Vector3.new(500,500,500)*Vector3.new(math.random(1,2)==1 and 1 or-1,1,math.random(1,2)==1 and 1 or-1)local f=Vector3.new(math.random(-100,100),100,math.random(-100,100))l:spawn(J.Mothership({goal=f,nextGoal=E}),J.Transform({cframe=CFrame.new(C)}))end for E in(l:query(J.Transform,J.Mothership)):without(J.Model)do local f=C.Assets.Mothership:Clone()f.Parent=workspace f.PrimaryPart:SetNetworkOwner(nil)l:insert(E,J.Model({model=f}))end for C,E,f in(l:query(J.Mothership,J.Transform)):without(J.Lasering)do if(f.cframe.p-E.goal).magnitude<10 then if E.lasered then l:despawn(C)else l:insert(C,E:patch({goal=E.nextGoal,lasered=true}),J.Lasering({remainingTime=1}))end end end for C,J,E in(l:query(J.Mothership,J.Model)):without(J.Lasering)do E.model.Roomba.AlignPosition.Position=J.goal end end return l
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Components = require(ReplicatedStorage.Shared.components)
local Matter = require(ReplicatedStorage.Lib.Matter)

local function spawnMotherships(world)
	if Matter.useThrottle(10) then
		local spawnPosition = Vector3.new(500, 500, 500)
			* Vector3.new(math.random(1, 2) == 1 and 1 or -1, 1, math.random(1, 2) == 1 and 1 or -1)

		local despawnPosition = Vector3.new(500, 500, 500)
			* Vector3.new(math.random(1, 2) == 1 and 1 or -1, 1, math.random(1, 2) == 1 and 1 or -1)

		local goalPosition = Vector3.new(math.random(-100, 100), 100, math.random(-100, 100))

		world:spawn(
			Components.Mothership({
				goal = goalPosition,
				nextGoal = despawnPosition,
			}),
			Components.Transform({
				cframe = CFrame.new(spawnPosition),
			})
		)
	end

	for id in world:query(Components.Transform, Components.Mothership):without(Components.Model) do
		local model = ReplicatedStorage.Assets.Mothership:Clone()
		model.Parent = workspace
		model.PrimaryPart:SetNetworkOwner(nil)

		world:insert(
			id,
			Components.Model({
				model = model,
			})
		)
	end

	for id, mothership, transform in
		world:query(Components.Mothership, Components.Transform):without(Components.Lasering)
	do
		if (transform.cframe.p - mothership.goal).magnitude < 10 then
			if mothership.lasered then
				world:despawn(id)
			else
				world:insert(
					id,
					mothership:patch({
						goal = mothership.nextGoal,
						lasered = true,
					}),
					Components.Lasering({
						remainingTime = 1,
					})
				)
			end
		end
	end

	for _, mothership, model in world:query(Components.Mothership, Components.Model):without(Components.Lasering) do
		model.model.Roomba.AlignPosition.Position = mothership.goal
	end
end

return spawnMotherships
