15 lines
639 B
Luau
15 lines
639 B
Luau
--!strict
|
|
local CollectionService = game:GetService("CollectionService")
|
|
local Spawn = {}
|
|
|
|
function Spawn.position(world: Instance, attack: boolean, fallback: Vector3, ordinal: number): Vector3
|
|
local points: {BasePart} = {}
|
|
for _, point in CollectionService:GetTagged(if attack then "AttackerSpawn" else "DefenderSpawn") do
|
|
if point:IsA("BasePart") and point:IsDescendantOf(world) then table.insert(points, point) end
|
|
end
|
|
if #points > 0 then return points[(ordinal - 1) % #points + 1].Position end
|
|
return fallback + Vector3.xAxis * ((ordinal - 1) % 5 - 2) * 3 + Vector3.zAxis * (math.floor((ordinal - 1) / 5) * 3)
|
|
end
|
|
|
|
return Spawn
|