What do you want to achieve? Keep it simple and clear!
I want to make the player’s character transparent locally including all their hats, clothes and other accessories (they’ll be invisible only for themselves, others will be able to see them)
What is the issue? Include screenshots / videos if possible!
I can’t seem to get it working.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried using this localscript in workspace (I wrote it myself):
local player = game.Players.LocalPlayer
for i, v in pairs(player.Character:GetChildren())
v.Transparency = 1.0
end
Utilize :GetDescendants() on the Character model so that everything on the first layer and every subsequent item inside of each of those Instances will be looked for.
In its current state, you’re only accessing everything on the first layer of the Character with :GetChildren()
for _,item in ipairs(player.Character:GetDescendants()) do
if item:IsA("BasePart") then -- We are checking for this because BaseParts have a Transparency property -- this will prevent the code from erroring if it finds an object that is not a BasePart
item.Transparency = 1
end
end
local player = game:GetService("Players").LocalPlayer
repeat wait() until player.Character
for _,v in pairs(player.Character:GetChildren) do
if v:IsA("BasePart") then
v.Transparency = 1
end
end
--Variables--
local character = game:GetService("Players").LocalPlayer.Character or game:GetService("Players").LocalPlayer.CharacterAppearanceLoaded:Wait()
--Script--
for i, child in ipairs(character:GetChildren()) do
if child:IsA("BasePart") and child ~= character:FindFirstChildWhichIsA("Humanoid").RootPart then
child.Transparency = 1
elseif child:IsA("Accessory") then
child:WaitForChild("Handle").Transparency = 1
end
end
Insert the LocalScript into game > StarterPlayer > StarterPlayerScripts:
As you can see, this script is different from others. Why?
We need to loop through every child when the character is fully loaded. If it isn’t fully loaded yet, it will not make every part transparent. player.CharacterAdded will fire when the player’s character model gets added into the game. player.CharacterAppearanceLoaded will fire when the player’s character model gets added into the game and every child is fully loaded. Therefore when we loop through every child, because we used player.CharacterAppearanceLoaded, everything is loaded correctly.
We are also checking if the child is not the HumanoidRootPart, this is not necaessary for making the character transparent, though it is necessary for making the character visible again.
A hat is not a BasePart, a hat is an Accessory. Though in the Accessory there is a part called “Handle” with a mesh in that part. Therefore if we’re checking a hat, the child is an Accessory, but the child of that Accessory is a part called “Handle”.
--Variables--
local localplayer = game:GetService("Players").LocalPlayer
--Script--
localplayer.CharacterAppearanceLoaded:Connect(function(character)
for i, child in ipairs(character:GetChildren()) do
if child:IsA("BasePart") and child ~= character:FindFirstChildWhichIsA("Humanoid").RootPart then
child.Transparency = 1
elseif child:IsA("Accessory") then
child:WaitForChild("Handle").Transparency = 1
end
end
end)
For anyone seeing this in the future, here’s the full script (it doesn’t make the “face” decal invisible but I don’t need that for now, to do that just check if the part’s name is head and run :FindFirstChild(“face”).Transparency = 1 on it):
local player = game:GetService("Players").LocalPlayer
repeat wait() until player.Character
for _,item in pairs(player.Character:GetChildren()) do
if item:IsA("BasePart") then
item.Transparency = 1
elseif item:IsA("Accessory") then
local handle = item:WaitForChild("Handle")
handle.Transparency = 1
end
end