So, you don’t want them to overlap basically?
Code
function taskcontroller.placeTasks()
local getPlacements = workspace.TaskPlacements:GetChildren()
local getTasks = rs.tasks:GetChildren()
local positionstaken = {}
for i = 1, #getTasks do
local chosenTask = getTasks[math.random(1,#getTasks)
local randomPlacement
local function set()
local num = math.random(1,#getPlacements)
if not positionstaken[getPlacements[num]] then
randomPlacement = getPlacements[num]
table.insert(positionstaken, getPlacements[num])
else
set()
-- Be careful, this can crash your game if all placements are taken!
end
end
set()
local copy = chosenTask:Clone()
copy.Position = randomPlacement.Position
copy.Parent = workspace.CurrentTasks
end
end
Edit : When you said “i tried deleting them when they are occupied”, I just realized theres a way more better way than this.
Delete randomPlacement and move local getPlacements inside the for loop
2 Likes
So something like this?
Edit: Nevermind I think I fixed it! Thanks for the help!
1 Like