I have made a script that makes you invisible
this is the script
I
I
I
function ChangePlayerTransparency(plr:Player, Transparency)
local Char = plr.Character
for i, v in pairs(Char:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
if v.Name == "Head" then
v.face.Transparency = Transparency
end
v.Transparency = Transparency
elseif v:IsA("Accessory") then
v.Handle.Transparency = Transparency
end
end
It works but not as i expected basically i have an ball too as an character if u spawn the ball becomes invisible too but i dont want it only the avatar will become invisible
for i = 1,#decals do
decals[i]:Clone().Parent = marble
end
while true do
wait()
marble.BodyAngularVelocity.AngularVelocity = Vector3.new(char.Humanoid.MoveDirection.z * 32,0,char.Humanoid.MoveDirection.x * -32)
marble.BodyAngularVelocity.MaxTorque = Vector3.new(5000,5000,5000)
if char.Humanoid.MoveDirection == Vector3.new(0,0,0) then
marble.BodyAngularVelocity.MaxTorque = Vector3.new(0,0,0)
end
end
end)
You are detecting the body parts with GetChildren, so the solution is you can put the ball inside any body part so the script will not detect it. (make a custom folder and put the folder inside the character and put the ball inside)
Why have 2 seperate scripts handling the invisibility and the ball?
function ChangePlayerTransparency(plr: Player, Transparency)
local Char = plr.Character or plr.CharacterAdded:Wait()
for _, v in pairs(Char:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
if v.Name == "Head" and v:FindFirstChild("face") then
v.face.Transparency = Transparency
end
v.Transparency = Transparency
elseif v:IsA("Accessory") and v:FindFirstChild("Handle") then
v.Handle.Transparency = Transparency
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
ChangePlayerTransparency(plr, 1)
local HRP = char:WaitForChild("HumanoidRootPart")
local marble = Instance.new("Part")
marble.Size = Vector3.new(5,5,5)
marble.BrickColor = BrickColor.White()
marble.Transparency = 0
marble.Name = "Marble"
marble.Position = Vector3.new(0, -0.5, 0)
marble.Shape = Enum.PartType.Ball
marble.Parent = char
marble.Material = Enum.Material.SmoothPlastic
local Velocity = Instance.new("BodyAngularVelocity")
Velocity.Parent = marble
local Hum = char:WaitForChild("Humanoid")
local Weld = Instance.new("Weld")
Weld.Parent = marble
Weld.Part0 = HRP
Weld.Part1 = marble
Hum.PlatformStand = true
local decals = script:GetChildren()
for i = 1,#decals do
decals[i]:Clone().Parent = marble
end
while true do
wait()
marble.BodyAngularVelocity.AngularVelocity = Vector3.new(char.Humanoid.MoveDirection.z * 32,0,char.Humanoid.MoveDirection.x * -32)
marble.BodyAngularVelocity.MaxTorque = Vector3.new(5000,5000,5000)
if char.Humanoid.MoveDirection == Vector3.new(0,0,0) then
marble.BodyAngularVelocity.MaxTorque = Vector3.new(0,0,0)
end
end
end)
end)
All I added is v:FindFirstChild("face") in if v.Name == "Head" and v:FindFirstChild("face") then because some avatars [Like the one I have (because I tested it in studio), don’t have faces and then the function won’t be able to finish.]
Hey I have a question I added the EXACT same script i added this to my other game now it doesnt hide the accessorys somewhy and I get no errors it hides everything but accessory
Try this script, it hides everything except the ball:
function ChangePlayerTransparency(plr: Player, Transparency)
local Char = plr.Character or plr.CharacterAdded:Wait()
for _, v in pairs(Char:GetDescendants()) do
if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" and v.Name ~= "Marble" then
if v.Name == "Head" and v:FindFirstChild("face") then
v.face.Transparency = Transparency
end
v.Transparency = Transparency
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
ChangePlayerTransparency(plr, 1)
local HRP = char:WaitForChild("HumanoidRootPart")
local marble = Instance.new("Part")
marble.Size = Vector3.new(5,5,5)
marble.BrickColor = BrickColor.White()
marble.Transparency = 0
marble.Name = "Marble"
marble.Position = Vector3.new(0, -0.5, 0)
marble.Shape = Enum.PartType.Ball
marble.Parent = char
marble.Material = Enum.Material.SmoothPlastic
local Velocity = Instance.new("BodyAngularVelocity")
Velocity.Parent = marble
local Hum = char:WaitForChild("Humanoid")
local Weld = Instance.new("Weld")
Weld.Parent = marble
Weld.Part0 = HRP
Weld.Part1 = marble
Hum.PlatformStand = true
local decals = script:GetChildren()
for i = 1,#decals do
decals[i]:Clone().Parent = marble
end
while true do
wait()
marble.BodyAngularVelocity.AngularVelocity = Vector3.new(char.Humanoid.MoveDirection.z * 32,0,char.Humanoid.MoveDirection.x * -32)
marble.BodyAngularVelocity.MaxTorque = Vector3.new(5000,5000,5000)
if char.Humanoid.MoveDirection == Vector3.new(0,0,0) then
marble.BodyAngularVelocity.MaxTorque = Vector3.new(0,0,0)
end
end
end)
end)
I still can see my accessory i get no errors the script
function ChangePlayerTransparency(plr: Player, Transparency)
local Char = plr.Character or plr.CharacterAdded:Wait()
for _, v in pairs(Char:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" and v.Name ~= "Marble" then
if v.Name == "Head" and v:FindFirstChild("face") then
v.face.Transparency = Transparency
end
v.Transparency = Transparency
elseif v:IsA("Accessory") and (v:FindFirstChildOfClass("BasePart") and v:FindFirstChild("Handle")) then
v.Handle.Transparency = Transparency
end
end