I am working on a game and I have a script in StarterCharacterScripts. I already have the whole script finished except for this part; I want it to make players invisible, including their tool. What code would I use?
How do I make the player invisible?
1 answer
-- Loops through all of the character's children
for _, item in pairs (character:GetChildren()) do
-- If the item is a part (This means that this is probably a body part), set the transparency to 1 (100% Transparent)
if item.ClassName == "Part" then
item.Transparency = 1
-- If the item is an accesssory or a tool, loop through all of the accessory's children
elseif item.ClassName == "Accessory" or item.ClassName == "Tool" then
for _, accessoryPart in pairs (item:GetChildren()) do
--If it finds a part, set it to transparent
if accessoryPart.ClassName == "Part" then
accessoryPart.Transparency = 1
end
end
end
end
Basically, this will search through the character for any part, and set it transparent. Though if the character has accessories, then the script will look through the accessory and set the parts to transparent. Though, keep in mind that if the player pulls out an other tool, the tool might not be transparent, so you have to make something that will check for when the player equips a tool, set the parts in it to transparent
3 comments
you shouldnt use .ClassName == "Part", use :IsA("BasePart"), :IsA("Accoutrement"), and :IsA("Tool")
There's nothing wrong with comparing the ClassName property. IsA just gives you the option for checking base classes, which he's not doing here. I'd recommend using IsA for everything, but it's not required, and it doesn't deprecate ClassName.
Oh. I was unnaware that :IsA() was a better way to check ClassNames.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
I don't need fancy fades or anything complicated like that. I am just stuck and confused...