Region3 issues when trying to create a region on an angle

Hi all,

I am trying to create a few regions to check for players.

The issue faced is that when creating a region 3(see below pic1) in a rectangle shape, I get the correct region however when trying to create the same thing on an angle, the shape does not follow,
— Image below shows a working region I created, rectangular shape.


– Below shows an attempt at making region3 on a 45* angle.

I have tried to look at several posts regarding region3s, with ideas such as creating a part and getting the top and bottom part of it to create a region however it only returned an unexpected result.

any help would be appreciated.


Region3s are Axis-Aligned so I dont believe they can have an angle

What do you think would be the best solution to this? I mean, would you instead use :PartsInBoundBox on a specific part to counter this issue?

Use WorldRoot:GetPartBoundsInBox().

Have implemented this in my script. What I am trying to achieve is get all players within a certain region/box . still facing difficulties

Script below

``lua

	local Part = workspace.One

	local PartsBoundingBox = workspace:GetPartBoundsInBox(Part.CFrame, Part.Size)
	
	for i, v in pairs(PartsBoundingBox) do
	print(v.Parent)
	if Players:GetPlayerFromCharacter(v.Parent) then
		player += 1 
	end
	
	end
	print(player)

Whilst it does return expected results, (left foot, arm, etc…) which can be used to find player character, when trying to add get the number of players within that region by using player value, an incorrect result is returned. e.g if 2 players in box, it would return 3 instead 2 and so on… I can’t seem to find to do this properly.

  • Please note this is all running within a while loop however there is a debounce on it, so nothing is repeating itself more than once.

Much appreciated

You might be getting the wrong number of players because you’re detecting the same players multiple times and still incrementing the counter. Try this instead:

local PlayersService = game:GetService("Players")
local boundingBox = workspace.One
local players = {}


for _, part in workspace:GetPartBoundsInBox(boundingBox.CFrame, boundingBox.Size) do
	local player = PlayersService:GetPlayerFromCharacter(part.Parent)
	
	if player and not table.find(players, player) then
		table.insert(players, player)
	end
end


local numPlayers = #players
print(numPlayers)