How to spawn model randomly in a certain area

I was looking for ways to spawn a model at a random place inside a area but I cant find a way will make sure it isn’t colliding with anything else

Is there an easy way to do this?


You could set a bunch of parts around the map and have the game choose a random number assigned to any random part. After that in theory you should be able to do Model:MoveTo(part.position) and it will teleport the model to the invisible part.

local Rndm = --Random object.

local function RandomSpawn(Object, MinVec, MaxVec) --Object (model or part), minimum vector, maximum vector.
	Object:PivotTo(, MaxVec.X), Rndm:NextNumber(MinVec.Y, MaxVec.Y), Rndm:NextNumber(MinVec.Z, MaxVec.Z)))

local Part ="Part")
RandomSpawn(Part,, -2, -2),, 2, 2))
print(Part.Position) --1.7936413288116455, 1.355130910873413, 0.4525333344936371
1 Like

What if it picks one that already has one on it?

Give the part a Boolean Value that sets to true if there is already a model on it, then set the conditions of the model moving to a part to requiring the parts value to be false. If it doesn’t meet the conditions have it reselect until it does. Personally I feel like repeat loops would work best for this. If you need help better understanding what I said, simply reply to my message.

1 Like

Thanks I will try and make this now!

1 Like