How would I prevent players putting their camera through transparent parts?

I have a cafe build and I have an invisible barrier to stop players from entering the counter, but they can put their camera through there and grab the food. I was wondering if there was a method of preventing this, and if it is, how?

Any help is much appreciated. Thanks in advance!

1 Like

There are multiple ways to do this. You could check if the player is allowed in the café, check how far away they are from the food, or turn shift lock off. (If that’s the way that they can clip there camera through the wall.)

Tell me what one would best suit you and I can explain it for you if you would like.

2 Likes

There’s a setting under StarterPlayer/Player called DevCCameraOcclusionMode with two settings;

However, I do not recall whether zoom stops the camera moving through transparent parts.

You could create a very simple LocalScript that sets the camera’s MaximumDistance depending on a RayCasst shot from the Camera’s Focus to the Camera’s CFrame.
If the RayCast hits anything, set the MaximumDistance equal to the distance of the cast.

3 Likes

Thank you very much! This fixed the problem.