I'm making a simulator and I need to be able to have objects spawn randomly around my map have any suggestions on how I would do it?
✓ ANSWER ACCEPTED
I need a way to make some objects randomly spawn around my map. Have any ideas?
1 answer
✓ Accepted answer
Hey! So to make a part spawn randomly around the map you're going to need to use math.random. math.random is a function that chooses a random number between the specific numbers given. For example if I were to do math.random(1,50) it would choose a number between 1 and 50. So to do this you would do something like this:
while true do
wait(3) -- However long you want to wait before another object spawns
local Object = Instance.new("Part", game.Workspace)
Object.BrickColor = BrickColor.new("Really black")
Object.Size = Vector3.new(1.77, 1.81, 1.73)
local xPos = math.random(0,50) -- How far you want the part to spawn on the x axis
local yPos = 0.905 -- How far you want the part to spawn on the y axis (this specific coordinate should spawn it right on a baseplate)
local zPos = math.random(0,50) -- How far you want the part to spawn on the z axis
Object.Position = Vector3.new(xPos,yPos,zPos)
end
This code should make a black cube spawn around the map every 3 seconds. If you have any questions just leave a reply. Hope this helped!
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Why use while true do? Just use while wait() do. Other than that that's good, just make sure they know that 0 is the minimum, and 50 is the maximum.