GUI Face Censoring

Hey guys, I was playing a game called Repleh County Archives 2 and I saw that they censored character faces like a real body cam video. I got an idea to do this in my game but I have one problem, I put the gui in for a characters face but, the only way i fugyured out how to get it like the game was by ticking the AlwaysOnTop button which would show it even when something is in the way. Ill show you Repleh County Archives 2 video and my own game.

robloxapp-20240412-1812071.wmv (4.0 MB) - Repleh County Archives 2
robloxapp-20240413-0956140.wmv (3.7 MB) - My game

2 Likes

That effect can be achieved through a combination of AlwaysOnTop and manual checks whether the head is visible or not.

I’ve attached an example script and a video showing off the effect, but there are some substantial improvements to be made if you want to include the effect in an actual game.

local camera = game.Workspace.CurrentCamera
local target = game.Workspace.R6.Head

function updateVisibility()
	local cameraPos = camera.CFrame.Position
	local raycastParams = RaycastParams.new()
	
	raycastParams.FilterDescendantsInstances = {target.Parent, game.Players.LocalPlayer.Character}
	
	local raycastResult = game.Workspace:Raycast(cameraPos, target.Position - cameraPos, raycastParams)
	
	if raycastResult ~= nil then
		target.BillboardGui.Enabled = false
	else
		target.BillboardGui.Enabled = true
	end
end

game:GetService("RunService").RenderStepped:Connect(updateVisibility)

1 Like

Hey, Thanks so much man this is exactly what I needed. Thanks for putting a script too so I can learn a little bit!

So actually I ran into a problem, when I put the gui into the head and renamed the correct things in the script, the output puts an error that says the head is not a valid member of workspace.rig and rig is the name of what im testing it on, do you have any ideas? Also, I put the script into starter player scripts since the script worked for a sec in there but then it didnt.

Here’s a video -

here’s another video with no errors but it just only works close up -

The script I sent was a proof of concept - you’ll need to modify it to fit your own needs.

Here are some of the modifications you should consider:

Change the raycast’s filter (this is the one you’re probably having problems with)
My script ignores the player’s character and the parent of the target part, but you may need to ignore other parts (windows, invisible parts, …)
I recommend printing the raycastResult to debug this.

Allow for easier re-use
Put the effect parts in a common location, don’t assume that we also want to ignore the parent of the parts, allow checking for multiple at once, …

Don’t check if you don’t need to
Especially indoors, you probably won’t see it until you’re quite close. There’s no point in casting a ray across the entire map every frame.

Build the raycastParams once, not every frame
If you don’t need to dynamically change the parameters, you don’t need to rebuild the raycastParams every frame.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.