Pretty simple, spawn a clone inside a specific boundary called “boundary”. However, it’s not being copied as a proper rig. And the parts are being spawned separately, this is because it wouldn’t work spawning it as a whole model for some reason.
local workspace = game:GetService("Workspace")
local AI = workspace.R6
local boundary = workspace.Boundary
if not AI or not boundary then
print("Missing AI or boundary!")
return
end
local function spawnAI()
-- Create
local clone = Instance.new("Model")
local cloneParts = {}
-- Clone each part
for _, part in ipairs(AI:GetChildren()) do
if part:IsA("BasePart") then
local clonePart = part:Clone()
clonePart.Parent = clone
table.insert(cloneParts, clonePart)
end
end
local xMin = boundary.Position.X
local xMax = xMin + boundary.Size.X
local zMin = boundary.Position.Z
local zMax = zMin + boundary.Size.Z
for _, part in ipairs(cloneParts) do
local x = math.random(xMin, xMax)
local z = math.random(zMin, zMax)
part.Position = Vector3.new(x, boundary.Position.Y, z)
end
clone.Parent = workspace
print("Spawned AI")
end
spawnAI()
Not sure why you can’t get a model to clone as a whole.
Maybe selecting a PrimaryPart in the property window would help.
Here is the basic idea of cloning a model and putting it in the workspace:
local model = "YourModel" -- wherever your model is
local targetPart = "YourTargetPart" -- a location
local modelClone = model:Clone() -- clone the model
model.PrimaryPart.CFrame = targetPart.CFrame -- tell it where you want it
model.Parent = game.Workspace -- put it in the workspace
local AI = workspace:FindFirstChild("R6")
local boundary = workspace:FindFirstChild("Boundary")
if not AI or not boundary then
print("Missing AI or boundary!")
return
end
local function spawnAI()
-- Create
local clone = AI:Clone()
local xMin = boundary.Position.X
local xMax = xMin + boundary.Size.X
local zMin = boundary.Position.Z
local zMax = zMin + boundary.Size.Z
local x = math.random(xMin, xMax)
local z = math.random(zMin, zMax)
clone:PivotTo(CFrame.new(x, boundary.Position.Y, z))
clone.Parent = workspace
print("Spawned AI")
end
spawnAI()