I have these 'zones', which are just parts i have placed and rotated, with collision turned off and invisible. Child parts of these 'zones' should be considered as part of their parent 'zone'.
I tried to use OnTouched/OnTouchEnded, but it was unrelaible. So now I'm trying this, is this ok to do? It happens once a second since I need to be checking these zones for players constantly. I don't expect many zones, but they might be a bit big at times?
Anyway here's the lua:
for _, zoneData in spawnData do -- zone data includes some info about the zones
local playersInZone = {}
for _, part in ipairs(zoneData.parts) do -- parts is the zone itself and 'sub-zones' which are considered the same zone
overlapParams:AddToFilter(PlayerService:GetPlayers()) -- overlapParams created at the start of the script so it's not constantly created
local foundPartsOfPlayers = workspace:GetPartBoundsInBox(part.CFrame, part.Size, overlapParams)
for _, fpp in ipairs(foundPartsOfPlayers) do
local character = fpp.parent
local player = character and PlayerService:GetPlayerFromCharacter(character)
if player and not playersInZone[player] then -- dont want duplicates
table.insert(playersInZone, player)
end
end
end
end