I'm very new to Region3 stuff, I've never used or seen it before personally. I'm using it as I think it's a very good unexploitable system on detecting whether a player is in a lobby or in a map to change their health, but I'm wondering how can I find players who enter a Region3 area, so I can then change their maxhealth to math.huge?
The workspace
has a function called FindPartsInRegion3, which takes a Region3
object to do as it name implies: find the parts in that Region3
.
As you mentioned earlier, you have:
local a = Region3.new(Vector3.new(1, 1, 1), Vector3.new(10, 10, 10))
Now, what you need to do is make use of the FindPartsInRegion3
function of workspace
to retrieve all the parts in a
. For each part found, you need to determine if the part belongs to the character of a player or not. It can be done so like this:
local players = {} local a = Region3.new(Vector3.new(1, 1, 1), Vector3.new(10, 10, 10)) for _, part in pairs(workspace:FindPartsInRegion3(a, nil, math.huge)) do local character = nil -- In the case the part is a limb if part.Parent:FindFirstChild("Humanoid") then character = part.Parent -- In the case the part is part of an accessory elseif part.Parent.Parent:FindFirstChild("Humanoid") then character = part.Parent.Parent end if character then local player = game.Players:GetPlayerFromCharacter(character) if player and not players[player.Name] then players[player.Name] = player end end end
Now, the players
table will contain all the Player
s found in the specified Region3
, with the key being the Player
's name and the value being the Player
object.