How Can I Make the Avatar Invisible?

Alright, so I’m working on a project where you play as a cube. And, since you play as a cube, I have to do something with the avatar to make it go away. What I’ve decided to do is just make the avatar invisible.

I’m trying to achieve this by running through every child that belongs to the character’s model, (The Model that is the character in the Workspace) checking to see if it’s an object (In this case, I would have to check if it’s a part, then a mesh) and if it is, I need to set it’s transparency to 1.

However, I’m running into some problems. First, I need a way to scan through all of the Model’s children. Second, I need a way to scan through the children of the children. Yes, I do need to do that, as when I was looking through my avatar to see what kind of stuff I would need to hide, there were some meshes that where children of accessories.

How would I scan through these? Should I use some form of FindFirstChild, or would that not work in this case? Any help is appreciated.

Edit: Thanks to the help of @DarkDanny04, I managed to figure out how to hide the character. The code is right below this, and to hide the face, you can just change the if v:IsA("BasePart") then to if v:IsA("BasePart") or v:IsA("Decal") then. Have a great day, folks! :smile:

1 Like

GetDescendants() is what you are looking for

Is there an option to look for the descendants of some descendants? I’m worried it might skip over some objects when there are meshes that are descendants of it. How would I search for that?

If you used character:GetDescendants() It will get all the children of the character, and then say for example like an accessory, it will get the children of that too, and if theres a part in that accessory with another part, it will get all their children. It should get everything and not miss anything

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?