Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I clone a part to a random position inside another part?

How would I clone a part to a random position inside another part? I have tried different approaches to this problem, but the part always happens to appear in the middle of the part it needed to appear in.

1 answer

Okay, so this one'll need a liiiittle bit of work: You want your position to be within the part, so assuming they're not meshparts, unions, or anything else that would change the meaning of "inside" it, you may want to do something similar to this:

--NOTE: Untested
local PartA,PartB = --...
local MaxDisplacement=(PartA.Size-PartB.Size)/2
PartB.CFrame=PartA.CFrame * CFrame.new( --Goto A's CFrame, and displace by random xyz
	-MaxDisplacement.X+math.random()*MaxDisplacement.X*2,
	-MaxDisplacement.Y+math.random()*MaxDisplacement.Y*2,
	-MaxDisplacement.Z+math.random()*MaxDisplacement.Z*2
)

This discussion is preserved as it was. New answers, comments, and votes are closed.