How could math.random be used?

I created a script whereas a single part is cloned to make many copies of itself and randomly spawn in different areas.

I want it to spawn randomly around a certain area, like its rain, but i dont know how to do it
This is the script


This is what the rain looks like and where its spawning around (i dont want it to spawn around this area)

This is the place i want the rain to randomly spawn around in
Screenshot 2024-07-26 192528
This is the parts cframe
Screenshot 2024-07-26 192732
I may have not been clear enough or given enough info so please tell me if i need to provide more clarification

you could spawn a rainpart at a random position above the target part like this

local lowx = spawnPart.Position.X - spawnPart.Size.X/2
local highx = spawnPart.Position.X + spawnPart.Size.X/2
local lowz = spawnPart.Position.Z - spawnPart.Size.Z/2
local highz = spawnPart.Position.Z + spawnPart.Size.Z/2

local rng = Random.new()
rainPart.Position = Vector3.new(rng:NextNumber(lowx,highx), 100, rng:NextNumber(lowz,highz))
1 Like

This helped with my problem, thanks for the solution :+1:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.