top of page

Roblox Studio Region3


Understanding Region3

Region3 represents a volume created using two vector3 positions that are on opposite corners of a cuboid. The image above shows two parts called minPart, and maxPart. These represent the two positions that we will use. The green part called regionPart represents the invisible area or volume that the Region3 will represent. Finally the part named partInTheRegion represents a part that we will move back and forward through our new Region3 using the Tween Service.


Create The Project Above

In Roblox Studio create a new baseplate project and add the parts shown in the image to the workspace.

  • regionPart

    • Size(10,10,10)

    • Anchored = true

    • Transparency = 0.8.

    • Brickcolor = “Lime Green”

    • Position = (0, 5.5, -16)

  • minPart And maxPart

    • Size(1,1,1)

    • Anchored = true

    • BrickColor = “New Yeller”

    • minPart Position = (-7.214, 0.14, -16.157)

    • maxPart Position = (7.144, 10.543, -16.157)

  • partInTheRegion

    • Size(2,2,2)

    • Anchored = true

    • BrickColor = “Really red”

    • Position = (16.946, 5.025, -16.533)

Add a script to the ServerScriptService and name it createRegionScript. Add the following code to the script.

local rs = game:GetService("RunService")
local minCorner = workspace.minPart.Position
local maxCorner = workspace.maxPart.Position
local myRegion3 = Region3.new(minCorner, maxCorner)

workspace.minPart:Destroy()
workspace.maxPart:Destroy()
workspace.regionPart:Destroy()

local function CheckRegion()
	local partsInRegion = workspace:FindPartsInRegion3(myRegion3, nil)
	
	if #partsInRegion >= 1  then
		print(partsInRegion[1].Name)
	end
end
rs.Stepped:Connect(CheckRegion)

What is happening?

We create variables for the minPart and maxPart to represent their positions. These are then use to create the Region3 represented by the myRegion3 variable. As the parts we placed in the workspace were only placed there so we could visualise what is happening we can destroy them. Finally we use the run service to run the CheckRegion function every frame which uses the method FindPartsInRegion3 to return a table that we can loop through and use the conditional statement to print the name of the part in the region. To have the partInTheRegion part move through the region complete the next section.


Move A Part Through The Region

Select the partInTheRegion part in the explorer window and add a script to it. Name the script regionPartScript. Add the following code to the script.

local ts = game:GetService("TweenService")
local part = script.Parent
local info = TweenInfo.new(3,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,-1,true)
local goal = {}
goal.Position = Vector3.new(-12.598, 5.025, -16.533) 
local tween = ts:Create(part,info,goal)
tween:Play()

You should find that the part moves smoothly back and forward through the Region3 that we have created and the CheckRegion function prints the name of the moving part any time the part is inside the region. You can apply this same idea using characters in your game to do many things such as play music, do damage, or display messages.

117 views0 comments

Recent Posts

See All
bottom of page