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.
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.
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.
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)