What do you want to achieve? I want to make my character invisible only for the client.
What is the issue? I get the error Attempt to connect failed: Passed value is not a function but the script works because my character is invisible.
I placed the code in a localscript in StarterCharacterScripts
This is the code I wrote:
local character = game.Players.LocalPlayer.Character
function hideBParts(player)
wait(1)
for _, bparts in pairs(character:GetDescendants()) do
if bparts:IsA("BasePart") or bparts:IsA("Decal") then
bparts.Transparency = 1
end
end
end
game.Players.LocalPlayer.CharacterAppearanceLoaded:Connect(hideBParts())
Edit: If i run the code with Connect:(hideBParts) the function won’t run at all
Functions don’t work like that. In your code, you’re calling :Connect() which expects a function as it’s argument. However, you’re instead calling that function, and thus passing it’s return result. Which in your case is nothing, the solution is to remove the () on hideBParts
Just use LocalTransparencyModifier
This is an example:
function antiTrans(part)
if part and part:IsA("BasePart") and( part.Name=="Left Arm" or part.Name=="Right Arm" or part.Name == "Left Leg" or part.Name == "Right Leg") then -- checks if a part and is a arm
part.LocalTransparencyModifier =1
part.Changed:connect(function (property)
part.LocalTransparencyModifier = 1--Changes the local modifyer(client side only)
end)
end
end
for _,v in pairs(char:GetChildren()) do
antiTrans(v) -- adds all parts
end
Try changing the event to be something like localPlayer.CharacterAdded instead of CharacterAppearanceLoaded.
just now I tried using that event and the event didn’t fire, however CharacterAdded did. If you need certain aspects of the character to exist at any time, you can try using :WaitForChild()
If i do that I get the same result as CharacterAppearanceLoaded the character is invisible but I still get the error Attempt to connect failed: Passed value is not a function
Yes, that is what my previous reply mentions how to solve:
Functions don’t work like that. In your code, you’re calling :Connect() which expects a function as it’s argument. However, you’re instead calling that function, and thus passing it’s return result. Which in your case is nothing, the solution is to remove the () on hideBParts
To paraphrase a bit, just change it to :Connect(hideBParts) because connect wants a function, not the result of that function running.
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
if not player:HasAppearanceLoaded() then
player.CharacterAppearanceLoaded:Wait()
end
local function hideBodyParts()
task.wait(1)
for _, bodyPart in ipairs(character:GetChildren()) do
if bodyPart:IsA("BasePart") then
bodyPart.Transparency = 1
if bodyPart.Name == "Head" then
local face = bodyPart:FindFirstChild("face")
if face then
face.Transparency = 1
end
end
end
end
end
hideBodyParts()
Client-sided implementation, just to prove that it can work locally.