Limiting player position?

How would I restrict the player from going anywhere into the red zone, while still being able to walk inside the green zone without using any physical parts?

I’m thinking something to do with Region3, but I’m not sure. I need this to be efficient as there will be multiple of the zones and their CFrames will constantly change.

You apply a force client-side whenever they are close/inside the zone, outward from the zone, on Stepped. The amount of force depends on how far they are into the zone (capped at some reasonable value so they don’t fling out to nowhere when they are forcibly put inside the zone for whatever reason).

To find out if they are in the zone, simply transform the player’s CFrame into the object space of the zone, and then you can do a few simple axis value comparisons to find out whether the player is inside the zone, by how much, and what the shortest path out of the zone is.

It is easier to have a part client-side with a particular collision group though. What’s the reason you can’t use physical parts?

I don’t think I should be using physical parts because I’d have to update the positions of multiple big parts constantly which would be quite intensive as the game would have to recalculate physics, their properties, etc.

If the parts are really wide, you could instead use 4 thinner parts and make a box shape out of those. You’d be updating these client-side so there should not be as much networking cost, and physics updating cost is just something you should try out first before trying complicated solutions like this (that may or may not be more performance-intensive, actually, since you need to do all the checking/actions in Lua rather than letting the physics subsystem handle it).

Try first, then optimize if needed.

collision groups?

(nevermind just read the question and this feels out of place)

That doesn’t seem like a bad idea to me. That could work.

You could also just change the part’s CanCollide client-side, updating every few seconds to (hopefully) prevent exploits.

I would suggest using local parts. You could anchor them, and make them transparent. Together, that would take care of any physics lag, graphics lag, and server lag.

I need the parts to be large, when moving large parts it slows the game down a lot no matter if they are anchored or un-anchored.

How many large parts though? Have you even tried doing it with just parts? If you have them local, I don’t think you will have any major issues.

first, check if the parts REALLY need to be that large. if you are restricting players from exiting the map, you don’t need walls to be thousands of studs in height. you could also build multiple walls, and then add in a level of detail system so that only walls close to the player are loaded in.

(if you need a purely numerical approach, then construct a 3d bounding box to represent the player, and a bounding box for each area that needs to be restricted, then iterate through and check for collisions (many algorithms for this), and handle that data. do this locally for instant player feedback when going into restricted areas, and periodically server-side to prevent bugs)

Are you sure the lag isn’t caused by lighting recalculations? If so, that can be fixed with transparency. Additionally, be sure to move the blocks using CFrame. Setting the Position property requires much more calculation.

This wouldn’t work, because hackers could just remove the local script or the specific code from the local script and then go along their merry way. Hackers can edit everything on their client so trying to prevent hackers from the client is a useless exercise.

1 Like