What is the difference between Ray and Region3 and how to use both?

Okay, so i want to know what are the differences are of them and which would be better for what

Well, have you checked out the developer hub?



1 Like

yes, i have, and im still quite confused

Well what is your knowledge of scripting, if you are just starting out and want to know what these are, then it’ll be harder to explain.

my scripting skills are pretty intermediate

Rays & Region3s are quite different things and provide their own uses.

First of all, I’ll start with Rays. These are straight vectors with only one direction and can be used to find parts in a direction. To firstly create a Ray, you can use the Ray.new constructor and pass the Origin and the Direction:

local VectorOrigin = Vector3.new(0, 0, 0)
local VectorDirection = Vector3.FromAxis(Enum.Axis.Up) --// 1, 0, 0

local NewRay = Ray.new(VectorOrigin, VectorDirection) --// Makes a Vector from 0, 0, 0 to 1, 0, 0

Now, you can find a Part on the Ray yet also where it hit, the Normal (face) it hit and Material via the FindPartOnRay:

local HitPart, HitPosition, HitNormal, HitMaterial = workspace:FindPartOnRay(NewRay)

Additionally, there’s methods such as FindPartOnRayWithWhitelist and FindPartOnRayWithBlacklist.

Rays are great for Guns as they can be like shots and find who they hit etc.

Secondly, let’s talk about Region3s. These are essentially areas defined by a BottomLeft point and a TopRight point, with Region3s you can find what’s in a area at a given time. To create a Region3, you can use the Region3.new constructor:

local BottomLeft = Vector3.new(1,0,0)
local TopRight = Vector3.new(-1, 1, 0)

local NewRegion = Region3.new(BottomLeft, TopRight)

Now to find every part in the Region3 you use the FindPartsInRegion3 method, make sure to give math.huge as the maximum parts that can be found unless there’s a limit:

local FoundParts = workspace:FindPartsInRegion3(NewRegion, math.huge)

Similarly to Rays, there’s also FindPartsInRegion3WithWhiteList and FindPartsInRegion3WithIgnoreList methods.

Region3s are wonderful for making a zone area where players could get x2 stats or something similar.

A wonderful module which utilises both Rays and Region3s which I recommend is found here:

You should take a look into it!