Hi, I need help with a spawner. So, what I am supposed to make is to spawn robloxians into the map. I made invisible spawn points and got them into a folder. Then I scripted it so the script gets all the # of robloxians, and randomly spawns them in the map (the invisible spawners i put before).
The problem: It will only drop 1 character and won’t generate even more. Here is the script, I want it to keep generating not stopping after 1 robloxian.
It keeps saying “Position is not a valid member of model.”
local robloxians = game.ReplicatedStorage.Robloxians
local spawns = game.Workspace["Robloxian Spawns"]
while wait(2) do
local robloxianTable = robloxians:GetChildren()
local randomrobloxians = robloxianTable[math.random(1,#robloxianTable)]
local spawnsTable = spawns:GetChildren()
local randomSpawn = spawnsTable[math.random(1,#spawnsTable)]
local robloxianClone = randomrobloxians:Clone()
robloxianClone.Parent = game.Workspace.SpawnedEggs
robloxianClone.Position = randomSpawn.Position + Vector3.new(0,20,0)
robloxianClone.Anchored = false
end
Models don’t have a position property, so you need to use SetPrimaryPartCFrame()
local robloxians = game.ReplicatedStorage.Robloxians
local spawns = game.Workspace["Robloxian Spawns"]
while wait(2) do
local robloxianTable = robloxians:GetChildren()
local randomrobloxians = robloxianTable[math.random(1,#robloxianTable)]
local spawnsTable = spawns:GetChildren()
local randomSpawn = spawnsTable[math.random(1,#spawnsTable)]
local robloxianClone = randomrobloxians:Clone()
robloxianClone:SetPrimaryPartCFrame(CFrame.new(randomSpawn.Position + Vector3.new(0,20,0)))
robloxianClone.Anchored = false
robloxianClone.Parent = game.Workspace.SpawnedEggs
end
Also ensure that the models have a primary part for it to work.
If they’re spawning in a straight line, that’s probably because the spawns are also in a line. I don’t see why you’re getting that error, is what you sent the full script?
local robloxians = game.ReplicatedStorage.Robloxians
local spawns = game.Workspace["Robloxian Spawns"]
while wait(2) do
local robloxianTable = robloxians:GetChildren()
local randomrobloxians = robloxianTable[math.random(1,#robloxianTable)]
local spawnsTable = spawns:GetChildren()
local randomSpawn = spawnsTable[Random.new():NextInteger(1,#spawnsTable)]
local robloxianClone = randomrobloxians:Clone()
robloxianClone:SetPrimaryPartCFrame(CFrame.new(randomSpawn.Position + Vector3.new(0,20,0)))
for i,v in pairs(robloxianClone:GetDescendants()) do
if v:IsA("BasePart") then
v.Anchored = false
end
end
robloxianClone.Parent = game.Workspace.SpawnedEggs
end