Spawn spills at Random Places above Part

I’m making a spill system for a cafe where users can clean up spills for points. All of the other systems I’ve seen have had preset locations for spills to go. I was thinking about possibly having just one large invisible part with collisions off on the floor, and then spawning spills randomly on it.

I was thinking of possibly just spawning it with a preset Y axis, and then having it set a random location for the X and the Z, but I haven’t figured out a way to check if that location is actually in the set area that they’re supposed to go.

You could define min and max values for each coordinate taking into account the size of the part, here’s an example:

local part_size = area.Size
local part_position = area.Position

local min_X = part_position.X - part_size.X/2
local max_X = part_position.X + part_size.X/2

local min_Z = part_position.Z - part_size.Z/2
local max_Z = part_position.Z + part_size.Z/2

Then you could use math.random(min, max) to create a position taking into account the area of the part.

Hope this helps.

1 Like