Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Hiding the face in an invisibility script?

I made a KeyDown script that toggles invisibility for a character. Everything works fine, except I'm struggling to hide the player's face so it's not just floating around in mid-air. Any suggestions on how I would do that?

player = game.Players.LocalPlayer
mouse = player:GetMouse()
repeat wait() until player.Character
char = player.Character
faic = char.Head.face
char.Humanoid.DisplayDistanceType = "Viewer"
debounce = false
invisible = false

function invisibility()
	for x = 0, 2*math.pi, .1*math.pi do
		
		local waveform = 1/2-(math.cos(x/2)/2)
		
		for _, v in pairs(char:GetChildren()) do
			if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then v.Transparency = waveform
			elseif v:IsA("Hat") and v.Handle then v.Handle.Transparency = waveform end
		end
		
		wait()
	end
	
	char.Humanoid.HealthDisplayDistance = 0
	char.Humanoid.NameDisplayDistance = 0
	invisible = true
end

function visibility()
	char.Humanoid.HealthDisplayDistance = 100
	char.Humanoid.NameDisplayDistance = 100
	
	for x = 2*math.pi, 4*math.pi, .1*math.pi do
		
		local waveform = 1/2-(math.cos(x/2)/2)
		
		for _, v in pairs(char:GetChildren()) do
			if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then v.Transparency = waveform
			elseif v:IsA("Hat") and v.Handle then v.Handle.Transparency = waveform end
		end
		
		wait()
	end
	
	invisible = false
end

function onKeyDown(key)
	if key == "x" then
		if debounce == false then
			debounce = true
			
			if invisible == false then invisibility()
			elseif invisible == true then visibility() end
				
			debounce = false
		end
	end
end

mouse.KeyDown:connect(onKeyDown)

2 answers

I've got two suggestions for this.

  1. Create a fake head for the player, without their face decal. Hide the real head when they're invisible, and destroy the fake head when they're visible again.

  2. Destroy the face decal of the real head, store it somewhere, and add it back later.

If you need any help doing these, please feel free to ask. You seem to be a pretty advanced scripter, so I'm just assuming that you know how to do these things. However, if you do not, which is perfectly okay, feel free to ask, and I'd be more than happy to give details.

I would suggest cloning the face, putting it somewhere like Lighting or ReplicatedStorage, then destroy the face still on the head, and when you become visible, take the cloned face and put it in the player's head.

This discussion is preserved as it was. New answers, comments, and votes are closed.