#Trying to randomly spawn items in a specific area
1 messages · Page 1 of 1 (latest)
a cave gets assigned to a player when they join , and the second picture is the tunnel i want my ores to be able to spawn in
** You are now Level 4! **
Awesome, wish u good luck!
I'm not amazing at scripting but here is my thoughts on it. If the floor surface is flat, then you can probably do this:
local floor = path.to.floor (the floor of the cave)
local ore = path.to.ore (assuming this is a model with a primary part set in replicated storage or something like that)
while true do
local RNG = Random.new()
local XRandom = RNG:NextNumber(-x, x) -- replace with values of how far you want the ores to be placed on the x axis. for example: (-200, 200).
local ZRandom = RNG:NextNumber(-z, z) -- replace with values of how far you want the ores to be placed on the z axis.
--(to put this into perspective, imagine a top down view of the cave floor. Changing the x values will change the left and right position, while changing the z will change the up and down.)
local OreClone = ore:Clone()
OreClone.Parent = workspace
OreClone:PivotTo(floor.Position + vector3.new(XRandom, y, ZRandom) -- adjust the y value so the ore doesn't stick in the floor.
wait(25) -- or however long you want to wait before a new ore spawns
end
IMPORTANT: I'm not a great scripter, so if this doesn't work or make sense then honestly just put it in chat gpt and ask that to fix it for you, sorry but this is the best i got.
You can also just create a few parts on which the ores should spawn, add them to a table, then iterate through them and selecting a random one
so far ive been able to get some ores spawning in here but im now trying to figure out how to keep them from spawning inside of each other and inside of the walls
just check if any of the ore positions are equal to the random one you generated if not then proceed
this way wont work because they still can spawn too close
the best way is just to make a part equal in size or use the ore and check what it is colliding with
I mean is that really a big problem
plus math.random() can't produce decimals so nothing too close would spawn
so the closest thing would be off by 1 which is pretty noticeable imo
is he using math.random though?
how else are you gonna get randomness
lol
^^^
there is other functions
also your solution doesnt involve about the walls problem
you just limit the spawning range to be outside the walls at all times
not a big deal
seems tedious
** You are now Level 3! **
when all you have to do is make a region3 and check the parts in it
so you would just make sure it's not colliding with the walls?
yes also the ores are pretty big and it could still overlap
I mean if using a region3 is easier then go for it ig