I know how to check if a player enters a region but can't figure out when they leave it.
local Players = {} -- players in region gets stored into this table
local AreaPart = workspace.Area
function createRegion3FromPart(part)
local Size = part.Size
local Position = part.Position
return Region3.new(Position-(Size/2), Position+(Size/2))
end
function getPlayersInPart(part)
if part and part:IsA("BasePart") then
local newRegion = createRegion3FromPart(part)
local partsInRegion = workspace:FindPartsInRegion3(newRegion, nil, math.huge)
for i, v in pairs(partsInRegion) do
if game.Players:FindFirstChild(v.Parent.Name) then
local player = game.Players[v.Parent.Name]
table.insert(Players, player)
end
end
end
end
while true do
for i, v in pairs(Players) do
print(tostring(v))
end
getPlayersInPart(AreaPart) wait(1);
end

3 comments
Why are you checking in line 11 is part is a BasePart? That's unnecessary as that is always true.
What if I accidentally use a different instance thats not a BasePart?
You won't though.