How to make players not able to see through objects?

So I have a window made of glass on a build I did, my problem is that the player can simply put their camera outside the window and see whats outside like what im going to show:

image

Are there any things to prevent this happening?

5 Likes

This is probably not the best way to do this, but if you don’t want the camera to go through transparent parts, you could modify the camera scripts.

First, you’ll need to get the camera scripts. Play the game then go to StarterPlayer > StarterPlayerScripts > PlayerModule. Copy PlayerModule, stop the game then paste it into StarterPlayerScripts.

After that, go to PlayerModule > CameraModule > ZoomController > Popper. Go to line 128 and comment out or delete it, like this:

local function canOcclude(part)
	-- Occluders must be:
	-- 1. Opaque
	-- 2. Interactable
	-- 3. Not in the same assembly as the subject

	return
		--[[getTotalTransparency(part) < 0.25 and]] -- Comment out/delete this line
		part.CanCollide and
		subjectRoot ~= (part:GetRootPart() or part) and
		not part:IsA("TrussPart")
end

Now when you play the game, your camera shouldn’t go through transparent parts, like your windows.

14 Likes

Well this solved my problem but when I use shift lock it still can see through it.

What do you mean with that? Im not worried about them seeing what is already inside, im worried about the outside.

And the problem was solved but now im trying to know how to disable shift lock letting players see through object.

black glass, aka you cant see nothing thru it

I cant understand what you are saying. I already fixed the problem of being able to see through my window im just wanting to know how to stop shift lock being able to see through.

Maybe I wasnt clear but the image shows what I meant.

You are not being clear enough, I already said its “solved” but I still have problems at shift lock looking through

I think its because that you didn’t enable the CanCollide property of that window

If its enabled, it’ll be hard for the player to move the camera to outside the window

Actually it has can collide on, the part of players already being able to see it normally by putting camera outside was solved but if the player has shift lock on it can put camera outside.

1 Like

If you’re using the actual glass material you can put another part inside of the glass at transparency 0.05 and then you’ll be able to see through it but not move your camera through it.

5 Likes

Hey,
is there any other way to do that. Maybe using LUA ?

Thx

The camera scripts are a bit complicated so I might have missed something, but as far as I know, you can’t prevent your camera from going through transparent objects without directly modifying the camera scripts. This is because the transparency behavior is hard-coded into the scripts, so there doesn’t seem to be any kind of API for developers to change that using external scripts.

Maybe it’s possible to do this without touching the camera scripts by scripting your own camera logic, but I believe that would be unnecessarily complicated and end up just as complicated as the actual scripts.

You could also modify the camera scripts to include some API that allows you to modify the transparency behavior using outside scripts, but that still involves modifying the camera scripts anyway.

tl;dr: Transparency behavior seems to be hard-coded so you can’t use external scripts without modifying the camera scripts. Sorry.

1 Like

There is another way, a long time ago i used to do it by putting a mesh inside all the transparent parts, thx for this bc that was rediculous but just to let u know there is another way but u don’t want to do it

1 Like

By putting a mesh in, do you mean putting a BlockMesh/SpecialMesh in a part the same size as the transparent part and setting the mesh scale to 0?

That would definitely be tedious and hacky to do, especially if there are many transparent parts, but I can see that being useful actually if you want the camera to not go through certain transparent/invisible parts, instead of every part.

1 Like

yep that’s what I’m talking about and i actually had to do it on a larger scale back then so i made a plugin that did it for me, i don’t know where the plugin is anymore though