How can I check if a player is in a region3? (very new to scripting)

My game is a game about sword fighting. One person steps on one pad, another steps on another pad. This game is a bit like custom duels.

I want to make it so when a person steps on the pad, the pad turns green and if they leave the pad, it turns to grey. The next thing I am going to say is optional, if you are going to help me, you can include it but you dont have to. I also want it so that if two players are on one pad, the person that first went on the pad gets priority.

Script I made currently

local A = workspace.A
local b = workspace.B
local players = game:GetService("Players")
local playertable = players:GetPlayers()
local region = Region3.new(A.Position, b.Position)

while wait() do
	-- idk what to put here
end

Thank you!

1 Like

You’ll want to use GetPartBoundsInBox to get all parts inside the Region3 from which you can filter out HumanoidRootParts to get each player.

I HIGHLY recommend reading documentation for everything here so you fully understand how everything works, means and does.

Example:
Documentation: OverlapParams, GetPartBoundsInBox

local Players = game:GetService("Players")

local PointA = workspace.A
local PointB = workspace.B
local Region = Region3.new(PointA.Position, PointB.Position)

local Params = OverlapParams.new() -- Create parameters
-- Parameters are optional so you only use them for specific cases,
-- These are here just to serve as an example
Params.MaxParts = 100
Params.CollisionGroup = "PlayerGroup"
Params.RespectCanCollide = true

local PartsInRegion = workspace:GetPartBoundsInBox(
Region.CFrame, -- Set where the box is and it's orientation
Region.Size, -- Set size of the box
Params -- Set custom paramaters
)

-- Loop though all parts where you will check if a part is a descendant of a player's character
for Index, Part in PartsInRegion do
    print(Part.Name)
end