I made a script that chooses random positions behind the player for minions to stand in, but I wanted to make it so they can’t stand too near to each other. I put it in the repeat-until loop but it doesn’t seem to work, as they are still overlapping.
local part = script.Parent
local debounce = true
part.Touched:Connect(function(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid and debounce == true then
local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
if player then
local head = character.Head
local positions = {}
positions[1] = head.Position
for i, v in pairs(game.Workspace.Folder:GetChildren()) do
local magnitude
local position
local pos = #positions+1
local random
repeat
repeat random = math.random(-1,1) until random ~= 0
local X = math.sign(head.CFrame.LookVector.X)*24*math.random()*random
local Z = head.CFrame.LookVector.Z*math.random()*(-24)
position = head.Position + Vector3.new(X,1,Z)
positions[pos] = position
for a,b in ipairs(positions) do
magnitude = (position - b).Magnitude
if magnitude > 8 then break end
end
if magnitude < 8 then table.remove(positions, pos) end
until magnitude > 8
v.Humanoid:MoveTo(position)
end
debounce = false
end
end
end)