How Can I Make the Avatar Invisible?

Alright. In order to make those parts transparent, would I need to put them in some sort of table and use a For In Pairs loop, or is there a better way?

for i, v in pairs(character:GetDescendants()) do
--code here
end

This should do the job

Better code here for no errors

for i, v in pairs(character:GetDescendants()) do
      if v:IsA("BasePart") then
-- your code here
end
end

Ok, another quick question.

Let’s say I’m trying to put this effect on every character. I’m making one script and putting it in StarterCharacterScripts (Since I’ll be making changes to the character)

How do I get the player name? For now, I’ll just substitute it with my current Roblox username, but If I need to do this with other people, I’ll need to get their name. Does the StarterPlayer folder contain the assigned player’s username, or will I have to get it somehow else?

Well, if you’re going to do it from the StarterCharacterScripts, then you would use a local script. I assume you want the invisibility to be seen and recognized by the server, so that would not be viable. Instead use a PlayerAdded event and inside that a CharacterAdded event. The first parameter of the PlayerAdded event is player, and that’s how you will get the player. And from there you can just do player.Name (this script would go in serverscriptservice)

So would I take the script out of StarterCharacterScripts and put it somewhere else instead, then?

Edit: I’m stupid, it says it would go in serverscriptservice at the end :skull:

Yeah I would have the script be in ServerScriptService and use the method that I said previously

Alright, let me go set that up and I’ll be back

Ok, I ran into a problem. How do I check if something is a part? I’m trying to use 2 to check if it’s a part or a mesh.

based on how I wrote the for loop above, you would do

if v:IsA("BasePart") then
--invisibility stuffs
end
1 Like

Ok, I just finished the code, and since I can’t get anything to work first try, there’s a bug.

For some reason, the code isn’t running. I put in a print() to see what was happening, and it didn’t print, so for some reason, the code doesn’t fire when I start the game.

Did I do something wrong? Here’s the code:

The Code
local Players = game:GetService("Players")



Players.PlayerAdded:Connect(function(player)

	local PlayerCharacter = workspace:WaitForChild(player)
	
	
	for i, v in pairs(PlayerCharacter:GetDescendants()) do
		
		
		if v:IsA("BasePart") then
			
			v.Transparency = 1
			
		else
			
			
			if v:IsA("MeshPart") then
				
				v.Transparency = 1
				
			end
			
			
		end
		
		
	end
	
	
end)

Instead of that do this

local PlayerCharacter = player.Character or player.CharacterAdded:Wait()

And just to confirm, this is a server script, correct?

New Project

Yep.

Ok, it’s working, but not all the way. It hid my head, but then stopped there, as it only went once and didn’t repeat. Do you know what happened?

Okay I tweaked the script a little because it was running the for loop before the character was entirely loaded. Try this instead

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function()
		local PlayerCharacter = player.Character or player.CharacterAdded:Wait()
		for i, v in pairs(PlayerCharacter:GetDescendants()) do
			if v:IsA("BasePart") then
				v.Transparency = 1
			end
		end
	end)
end)

2 Likes

Ok. This worked perfectly, but there’s one small issue. Not with the coding, but with something else. Whenever you hide the head, it hides the head, but not the face. Is there a way to hid the face as well, or could I just get away with deleting the head?

1 Like

Oh yeah just make this small edit if v:IsA("BasePart") or v:IsA("Decal") then

Alright! It worked! I just have one more question before I wrap this discussion up: Does BasePart include MeshParts?

Basepart includes meshparts and regular parts

Alright! :slight_smile: Thanks for your help, and have a fantastic day!