RegionService3 - Styxling/Feather GitHub Wiki
RegionService3 is a basic system for detecting players and parts within defined regions of the game world. By supplying position and size data, the module can determine if players (based on their HumanoidRootPart) or parts are inside various types of regions (box, sphere, cylinder, and rotated cylinder). It also provides methods to sort players by team.
Features
Player Detection Methods
-
PartIsInsideBox:
Checks if a given part is inside a box defined by a CFrame and size. -
GetPlayersInBox:
Returns a list of players whose HumanoidRootParts are within a box. -
GetPlayersInSphere:
Returns a list of players within a spherical region. -
GetPlayersInCylinder:
Returns a list of players within a cylinder (assumes flat surfaces face up and down; a default radius is calculated if none is provided). -
GetPlayersInRotatedCylinder:
Returns a list of players in a rotated cylindrical region defined by a start and end point with a given radius. -
GetPlayersInPart:
Returns a list of players whose HumanoidRootParts intersect with a given part. -
Team-Sorted Methods:
Methods such asGetPlayersInBoxSortedByTeams,GetPlayersInSphereSortedByTeams, etc., group detected players by their team.
Part Detection Methods
-
GetPartsInBox:
Returns a list of BaseParts within a box region. -
GetPartsInSphere:
Returns a list of BaseParts within a spherical region. -
GetPartsInCylinder:
Returns a list of BaseParts within a cylindrical region. -
GetPartsInPart:
Returns a list of BaseParts that intersect a specified part.
Usage Example
local Directory = require(ServerStorage.Directory.MainModule)
local RegionService3 = Directory("_replicated", "RegionService3")
-- Create a new region service object
local region = RegionService3.new()
-- Example: Get players within a box region
local boxCFrame = CFrame.new(0, 5, 0)
local boxSize = Vector3.new(20, 10, 20)
local playersInBox = region:GetPlayersInBox(boxCFrame, boxSize)
print("Players in box:", playersInBox)
-- Example: Get parts within a cylindrical region
local partsInCylinder = region:GetPartsInCylinder(boxCFrame, boxSize, 10)
print("Parts in cylinder:", partsInCylinder)
-- Clean up when done
region:destroy()