Hello devforum, I’m in need of support once again. I’ve working on a spawning system script but it isn’t working
Here’s the script
local orbs = game.ReplicatedStorage.Orbs:GetChildren()
local spawners = game.Workspace.Spawners
for i, v in pairs(spawners:GetChildren()) do
while wait() do
if v.Active.Value == false then
local random = math.random(1, #orbs)
local selectedOrb = orbs[random]
local clone = selectedOrb:Clone()
clone.Parent = v
clone.Position = v.Position
v.Active.Value = true
end
end
end
`
Well its a server script and it was placed in the Serverscript service
The problem I’m facing is that once I run the game no blocks seem to spawn at the desried locations
Although the script actually picks a random block but I don’t know why it isn’t working
Seems like your local variable, selectedOrb is resulting as an error (My assumption)
Try using this instead:
local RS = game:GetService("ReplicatedStorage")
local Spawners = workspace:WaitForChild("Spawners")
local Orbs = RS:WaitForChild("Orbs"):GetChildren()
for _, Spawn in pairs(Spawners:GetChildren()) do
while true do
if Spawn.Active.Value == false then
Spawn.Active.Value = true
local RandomOrb = math.random(1, #Orbs)
local SelectedOrb = Orbs[Random]
print(SelectedOrb)
if SelectedOrb then
local Clone = SelectedOrb:Clone()
Clone.Position = Spawn.Position
Clone.Parent = Spawn
end
end
wait(.1)
end
end
I don’t think you need the while loop in there. Also, always parent things at the end.
You should also use task.wait() instead of wait() now.
I’m not sure if this would work, but I feel it’s due to the random variable. So I changed it, try this out.
local orbs = game.ReplicatedStorage.Orbs:GetChildren()
local spawners = game.Workspace.Spawners
for i, v in pairs(spawners:GetChildren()) do
if v.Active.Value == false then
local getRandom = math.random(1, #orbs)
local selectedOrb = orbs[getRandom]
local clone = selectedOrb:Clone()
clone.Position = v.Position
v.Active.Value = true
clone.Parent = v
end
end
Unfortunately none of them seem to work well i figured that an alternate solution is to place the script in each spawner instead of getting the children from a folder
I am deeply grateful for taking your time and helping me with this script