How to Detect Player Leaving Region3

This is my first post, so I’m excited (and scared)!

Anyway, I am just beginning to experiment with Region3, and I have learned how to properly detect players who have entered a region, and I would like to know if there is an effective and straightforward method to detect if they have left said region. If not, perhaps suggestions as to how I could possibly go about doing that. My overall goal is to create a local render system for a city project that I am apart of to reduce lag for the average player.

Thanks in advance!

8 Likes

Are you wanting it to fire only when the player initially leaves or when they are not in the region at any time?

1 Like

I’m hoping to make fire initially after the player has left.

1 Like

This post shows an alternative to using region3. Though it’s concept might work with region3 (not sure though).

4 Likes

I’m not an expert in Region3, but I found something on scriptinghelpers, and I think it may help

2 Likes

I think I need to stick with region3 because eventually, all the parts inside that region will be rendered locally. I suppose I could do a system of model cloning from RepStorage with touch events. Thanks for your help, btw.

2 Likes

I was on that page a little earlier, and it seemed relatively unclear to me. I’m sure I’ll be able to figure it out eventually. Just wondering if anyone had a simple solution. Thank you for your help.

1 Like

I don’t know if this would work, but this is my last guess (I don’t use region3 a lot). You can detect when the player enters a region. You could say something like if not InRegion then halt code right after you do what you need. Not sure how this would work though, so I don’t have any examples.

1 Like

That’s an interesting thought. My mind right now is going towards something like table comparing, or something along those lines. Wouldn’t know how to do that.

1 Like

Not sure if this works but maybe you could setup a “listening” function, to detect when the player is no longer in the region by using FindPartsInRegion3WithWhiteList for example:

local HumaniodRootPart = ----HumaniodRootPart

function OnLeaveListener(region3,HumaniodRootPart )

local Player =  game.Workspace:FindPartsInRegion3WithWhiteList(region3,  {HumaniodRootPart} ) -- you might want to connect/integrate your enter region3 function
if Player  then
   While Player ~= nil do
    wait(.5)
    Player = game.Workspace:FindPartsInRegion3WithWhiteList(region3,  {HumaniodRootPart} )
   end
---Player Is no longer in the region3
end

end
2 Likes

Thanks for your reply! This seems like it could work. However, may I ask what the whitelist means?

1 Like

The FindPartsInRegion3WithWhiteList function, includes a WhiteList meaning that only Objects within the given table will be return. In other words its only looking for objects in the given object array( 2 parameter)

Another way you can detect if a player is leaving a region3 is by using some math and calculating the space in which the region takes up, after detecting if they are in the region3 you can test and see if the player’s position is no longer in said space

5 Likes

Oh I see now, makes sense. Thanks for your help. That sheds a new light on things. That’s why I like this forum, sometimes it’s nice to get second opinions from someone with an external perspective.

I’ll see if I can get your methods to work.

5 Likes