i made a script to randomly pick an ore to spawn inside of a cave thats owned by a player , but the ores are all spawning in the same spot , how can i make it so the ores can spawn in different spots inside the tunnel and not inside each other? im very beginner level at coding and roblox studio
#Make parts spawn in random places
1 messages · Page 1 of 1 (latest)
You can make multiple parts and place them around the cave then loop through them, add them to a table and select a random position then spawn the ore at that position
yep just make the parts invisible and canCollide = false
oh i have one big part for that , thats what nodeSpawn is
should i just make a bunch of those instead of 1?
yes
see the highlighted part is an invisible part in the actual tunnel floor
so i should make multiple parts for spawning ores , then add another loop to pick one of the parts and have some way to randomly pick a position on the part to actually spawn the ores
yeah
thanks guys ill try to figure it out!
ive made multiple parts for ores to spawn on and i added them into a table , but im stuck right now trying to figure out how to randomly pick one of the spawn points , then randomly pick an ore , then randomly pick a spot on the spawn point while also making sure the ores dont spawn inside of each other
I would do something like:
local randomNodeSpawn = NodeSpawns:GetChildren()[math.random(1, #NodeSpawns:GetChildren())]
local xOffset = (math.random() - 0.5) * randomNodeSpawn.Size.X
local zOffset = (math.random() - 0.5) * randomNodeSpawn.Size.Z -- math random gives a random decimal from 0 to 1, so if you minus 0.5 you can get a range of -0.5 to 0.5. You scale this to the size of the node, so you get a random distance from the centre of the node without it going out of it
local randomSpot = randomNodeSpawn.Position + xOffset + zOffset
local randomOre = Ores:GetChildren()[math.random(1, #Ores:GetChildren())]
Then you would clone the randomOre and set its position in the randomSpot
Actually no the randomspot wont work as the spawn is a vector3 and the offsets are numbers
I would say make it a vector3.new() but because the nodespawns are rotated it wont really work
local randomSpot = randomNodeSpawn.Position
+ randomNodeSpawn.CFrame.RightVector * xOffset
+ randomNodeSpawn.CFrame.LookVector * zOffset