So, ive got this script that is supposed to spawn 20 rocks inside the given area, and then only spawn more when there are less than 20, all the way back up to 20. i get no errors, but it doesnt spawn anything. a
local function GenerateRocks()
for i = 1, 20 do
local numberofrocks = workspace.Rocks:GetChildren()
local RockClone = game.ReplicatedStorage.Rock1:Clone()
if #numberofrocks == 20 then
break
else
RockClone.Parent = workspace.Rocks
local RandomX = math.random(-86.341, -71.519)
local RandomZ = math.random(136.349, 143.938)
RockClone.Position = Vector3.new(RandomX, 2, RandomZ)
end
end
end
GenerateRocks()

27 comments
This still doesnt resolve my issue. None of the rocks are spawning
Are you sure the rocks are not spawning, and they aren't just falling into the void?
I am sure that they aren't falling into the void
Well maybe try posting a video so others can better understand the problem and try to fix it
Make sure the positions are set correctly and show the revised version of the script
Just updated it, and the positions are correct
Put a GenerateRocks() on line 12
It's kind of working, but they keep spawning in the same place now
Are you getting an error in the output that says "invalid argument #2 to 'random' (interval is empty)"? If so, you need to reverse the order of the arguments in your RandomZ to math.random(136.349, 143.938)
If that works, be sure to mark the post as a solution!
Sorry, internet cut out. That didnt fix it,
No errors though
Well it worked for me I don't know why it wouldn't work for you, did you change line 7 to local RandomZ = math.random(136.349, 143.938)?
Yes. They are spawning, but only in one place, every single time, and more dont spawn when I destroy them
Well you haven't implemented the feature to spawn more when there are less than 20 yet
Oh. I see.
I've just updated the script
Make sure the rock in ReplicatedStorage does not have a weld, and to make it spawn more when rocks are destroyed you must check if a rock has been destroyed and fire GenerateRocks() again.
Wouldn't that just spawn 20 more rocks?
And also, I've made sure there are no welds, but it is a union
No, it wouldn't spawn 20 more rocks because you checked for the numberofrocks to not be 20 in order to spawn more rocks.
But I still don't know why they are all spawning in the same spot if there is only one Union in ReplicatedStorage called Rock1 with no welds and the script is in ServerScriptService, because it works for me
Well, im not really sure what to do at this point. Could you possibly link a video or image of what your workspace looks like?
I actually tried it on a test coding map I had, but I don't think the other things would affect the rock spawning thing. I boxed all of the things that matter: https://cdn.discordapp.com/attachments/980702393824055340/980703108453781545/unknown.png
This is the script that I use, and every 10 seconds the amount of "Rock1" in the folder "Rocks" is 20 https://cdn.discordapp.com/attachments/780140523088379906/980703736970244096/unknown.png
I cant view any of the images.
It works. I just had a really bad typo, Thanks for your help