what’s inside spawnfolder?
Is it the crates that need to be spawned, or the spawnpoints where crates can be spawned?
okay, so I don’t really get this but I’ll try, could you clarify after?
local base = workspace.genBase --goes unused in this snippet
local spawnsFolder = workspace.spawn
--please add local to local stuff, like is place used somewhere else or is it a local var?
local minCount = 3
local maxCount = 5
local spawns = spawnsFolder:GetChildren()
local count = #spawns--the length of the list
for i=1, math.random(minCount, maxCount) do
print(i)
--seems to be getting a random crate or spawnpoint from the list.
local place = spawns[math.random(1, count)]:Clone()
place.Parent = workspace
end
so that’s the version refined, but I know you’re not looking for that, from what I understand (english isn’t my native language sorry, sometimes i don’t get stuff)
you choose a random crate (or spawnpoint) from the spawns folder, and you want to place it somewhere, randomly, in an area?
if this is the case, you can get the positions of the X, (,Y if you want it to float, but otherwise make it half’the crate 's size Y) and Z axis of your area like so:
and then take the X position of the x axis aligned parts, and the Z position of the z axis aligned parts,
these will represent your min and max values.
then do something like this:
local maxX = -12.5
local minX = -39.5
local minZ = 24.5
local maxZ = 51.5
local randomPart = workspace.cube
randomPart.Position = Vector3.new(math.random(minX, maxX), randomPart.Size.Y/2, math.random(minZ, maxZ))
it’s about getting the bounds of your chosen area (must be a square).
then after getting the numbers you integrate them into your actual script:
--previous vars
local minX = --your minimum x
local maxX = --your maximum x
local minZ = --your minimum Z
local maxZ = --your maximum z
for i=1, math.random(minCount, maxCount) do
print(i)
--get target from list
local place = spawns[math.random(1, count)]:Clone()
place.Parent = workspace
--include position
place.Position = Vector3.new(math.random(minX, maxX), place.Size.Y/2, math.random(minZ, maxZ))
end
if you want your part to float, you can also get your minimum and maximum Y values and replace place.Size.Y/2 with math.random(minY, maxY).
hope this helps!
(please clarify if i was wrong here…)
edit:
I’ve added some stuff to my picture so you can see from which cube you read the X and Z axis:
for that example, you get those, but you can easily see that by using the move tool, since it has the blue and red arrows, you just take both parts on the blue axis their z value, the least z value is min, the other would become max, and you do the same for x axis, I picked those three but you don’t really need to pick those, as long as you follow your move tool.
edit:
after you read the values you can delete the parts, they are just for reading.
edit:
if you want your cubes to fall down, like some games have these crate drops from the sky or whatever, you set the Y axis to something really high, like 100 and set unanchored to false, your part will spawn randomly in the area, but really high and roblox will ensure it falls down and then it looks like it is raining, crates?