GetRandomPositionInsidePart()

function GetRandomPositionInsidePart(Part0: BasePart, Part1: BasePart)
return (Part0.CFrame * CFrame.new(Random.new():NextNumber(-(Part0.Size.X / 2) + (Part1.Size.X / 2), (Part0.Size.X / 2) - (Part1.Size.X / 2)), Random.new():NextNumber(-(Part0.Size.Y / 2) + (Part1.Size.Y / 2), (Part0.Size.Y / 2) - (Part1.Size.Y / 2)), Random.new():NextNumber(-(Part0.Size.Z / 2) + (Part1.Size.Z / 2), (Part0.Size.Z / 2) - (Part1.Size.Z / 2))))
end

I made this function to return a random CFrame within a BasePart, based on another BasePart. I don’t know how to explain it very well in text, but check out the video I recorded:

21 Likes

This could be good for something like making custom particles spawn randomly inside the given volume.

4 Likes

oh, yes, the script also adjusts the size so as not to go outside the area

1 Like