Detect when a player is in or not in a part

What I’m trying to do is when a player enters a part, the PlayerInBox bool is set to true. And when there is no longer any players in the hitbox, it’s set to false. I’ve tried using Region3, but I’m just really confused.

Sounds very much like an XY problem, why exactly do you need to find if someone is in a part?

Can you show the script? I don’t really understand what your trying to do.

Because when someone is near, something gets enabled.

You could’ve asked for a solution to the problem rather than a solution to an answer that you made up for your problem.

I personally wouldn’t use region3 in this case, but if you want to check if a player is within a certain distance from an object you could use magnitude to calculate the distance from the player to the object.

if humanoid.MoveDirection.Magnitude > 0 then  -- player is walking
    local distance = ((((PlayerX - ObjectX )^2) + ((PlayerX-ObjectX)^2) )^0.5)  -- Calculate distance between two points
    if distance < 10 then  -- Distance between the player an object is less than 10 studs (I think theyre studs?)
        print("player is close")

maybe use .Touched and .TouchEnded or you could use :GetTouchingParts() or you could use raycast i dont reccomend to use .Touched and .TouchEnded

I recommend using this module, it’s great for what you need.

 local Player = game:GetService("Players").LocalPlayer
 local OpenFrame = workspace.Info  --Declare variables

 OpenFrame.Touched:Connect(function(hit) --Check if it is a person
if hit.Parent == Player.Character then
	script.Parent.Notifier.Frame.Visible = not script.Parent.Notifier.Frame.Visible --Here it says that while you are playing the part called info, that the frame is open.

use a custom module for it.

you can simply reference when a player has entered/exited a zone with:

    print(player.Name.." entered the zone!")

    print(player.Name.." entered the zone!")