Attempt to connect failed: Passed value is not a function

  1. What do you want to achieve? I want to make my character invisible only for the client.

  2. 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

1 Like

Change (hideBParts()) to (hideBParts)

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

If I change (hideBParts()) to (hideBParts) the function won’t run at all

Yes it will. Give it a try and let me know the result.

1 Like

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
1 Like

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()

1 Like

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.

If i change (hideBParts()) to (hideBParts) the function won’t run at all I think its because I load the player after the slection screen with

	player:LoadCharacter()
	game:GetService("Players").CharacterAutoLoads = true

I found what whas the issue:

game.Players.LocalPlayer.CharacterAppearanceLoaded:Connect(functionname)

only worked on a server-sided and script not in my localscript.

Thank you all for wanting to help me!

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.

1 Like