#Trying to randomly spawn items in a specific area

1 messages · Page 1 of 1 (latest)

warm jay
#

i want to have 6 seperate caves that each belong to a player , and in each cave i want there to be randomly generated ores spawning in them , i started writing a script for it but cant figure how to get it working , roblox studio and coding noob

#

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

rotund martenBOT
#

studio** You are now Level 4! **studio

hollow fiber
#

Awesome, wish u good luck!

gentle spruce
#

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.

sick mantle
#

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

warm jay
#

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

whole ermine
olive cloud
olive cloud
whole ermine
#

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

olive cloud
whole ermine
#

lol

olive cloud
#

there is other functions

#

also your solution doesnt involve about the walls problem

whole ermine
#

you just limit the spawning range to be outside the walls at all times

#

not a big deal

olive cloud
#

seems tedious

rotund martenBOT
#

studio** You are now Level 3! **studio

olive cloud
#

when all you have to do is make a region3 and check the parts in it

whole ermine
olive cloud
whole ermine
#

I mean if using a region3 is easier then go for it ig