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

How to use Region3?

Okay so I don't really understand how Region3 works. I know how to plug it in and stuff. But what im trying to do is get a Vector3 value from the Region3 value. I want to make a region where crates fall from but i want to fall from different places with the same region

for example: a Region that is 10 x 30x10 which translates to code -- Region3.new (Vector3.new(10,30,10), Vector3.new(WhateverPosition)) I want to extract random Vector3 values within the 10x30x10 Region. With the value i get with math.random is the Vector3 value of the Position Crate will spawn and fall down to the baseplate. Any Idea how to do this?

2 answers

✓ Accepted answer

This does not require a region3. A region3 is used to get parts within the given boundaries, but you're just trying to spawn parts in a random area within boundaries. To simulate this, just use 3 random values for the x, y, and z for the part's position.

I made an example script that generates rain in a small area.

local part = Instance.new("Part") --create a template for the part
part.FormFactor = "Custom"
part.BrickColor = BrickColor.new("Really blue")
part.Size = Vector3.new(0,2.5,0)
part.TopSurface = "Smooth"
part.BottomSurface = "Smooth"

local function ran(pos,x,y,z) --a function that returns a random position within the specified region
	return pos + Vector3.new(math.random(-x/2,x/2),math.random(-y/2,y/2),math.random(-z/2,z/2)) --Returns a random position around the given region. "pos" is the center of the region, and the seperate coords are corresponding radius.
end

while true do
	local clone = part:Clone() --clone the part
	clone.Transparency = math.random(50,90)/100 --randomize its transparency
	local ang = CFrame.Angles(math.rad(math.random(-10,10)),math.rad(math.random(1,360)),0)--creates a randomized rotation for the part
	local pos = ran(Vector3.new(0,100,0),10,30,10) --creates a random position within the region
	clone.CFrame = CFrame.new(pos)*ang --gives the part the random position and rotation
	clone.Parent = workspace --parents part to workspace
	clone.Touched:connect(function() --destroy part when it touches another object
		clone:Destroy()
	end)
	wait(0.1)--stall code
end

There is no way to derive a random point from a region3. Instead, do 3 math.randoms for your x, y, z values and construct a Vector3.

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