How to calculate the region over a character

So I am trying to calculate the region over a r15 character. Like this:

local RunService = game:GetService("RunService")

local part = script.Parent

local pos1 = part.Position - (part.Size / 2)
local pos2 = part.Position + (part.Size / 2)

local region = Region3.new(pos1, pos2)

RunService.Heartbeat:Connect(function()
	local partsInRegion = workspace:FindPartsInRegion3(region, nil, 1000)
	for i, part in pairs(partsInRegion) do
		if part.Parent:FindFirstChild("Humanoid") ~= nil then
			print("has entered the region")
		end
	end
end)

but with a player.
The only problem is with getting a region over a player is I don’t know how to find the two points, pos1(position1) and pos2 on the character, as seen in the sample code.

2 Likes

Huh, is there a reason why your using Region and not a .Touched event? You could always weld a invisible non collideable part that is as big as the hitbox of the character and any time anything touches that box it runs the touched event.

1 Like

I think what you’re looking for is:

local pos1 = Character.HumanoidRootPart.Position - (part.Size / 2)
local pos2 = Character.HumanoidRootPart.Position + (part.Size / 2)

Then depending on whether it’s a local script or a server script, you would do:

-- client
local Character = game.Players.LocalPlayer.Character

-- server: there's too many options to name and I don't know the particular
-- use case, so I'll leave it up to you

The Character’s HumanoidRootPart is the most reliable part for region checking, or any character checking in particular.

2 Likes

check this out, maybe its what you need

1 Like