Attempt to connect failed: Passed value is not a function

hiii
I am having a trouble with this;

local function CreateInstances(Data)
	for _,info in pairs(Data.Humans) do
		local InventoryTemplate = script.Parent.Templates.InventoryTemplate:Clone();
		local ParentTo = RealInventory.HumanSkills;
		InventoryTemplate.Parent = ParentTo;
		InventoryTemplate.TextLabel.Text = info.Name;
		Connections[InventoryTemplate] = {}
		InventoryTemplate.TextLabel.MouseEnter:Connect(StartInputConnection(InventoryTemplate));
		InventoryTemplate.TextLabel.MouseLeave:Connect(EndInputConnections(InventoryTemplate));
	end;
	for _,info in pairs(Data.Bacons) do
		local InventoryTemplate = script.Parent.Templates.InventoryTemplate:Clone();
		local ParentTo = RealInventory.BaconSkills;
		InventoryTemplate.Parent = ParentTo;
		InventoryTemplate.TextLabel.Text = info.Name;
		Connections[InventoryTemplate] = {}
		InventoryTemplate.TextLabel.MouseEnter:Connect(function()
			StartInputConnection(InventoryTemplate)
		end)
		InventoryTemplate.TextLabel.MouseLeave:Connect(function()
			EndInputConnections(InventoryTemplate)
		end)
	end;
end;

Any idea what it might be?
Error;

Attempt to connect failed: Passed value is not a function
at this lines
image

The error means that the thing inside the :Connect() is not a function, I suppose it comes from your StartInputConnection, can you please send it here :slight_smile:?

Also, I see that you try to connect to function which you sent parameters to

Does your StartInputConnection or EndInputConnection return a function? Because you can’t connect to a function that you gave parameters to like that, instead, open an 'anonymous function’s in the connect and call the custom function from there.

1 Like

No!
Doesn’t returns anything :stuck_out_tongue:
Just connects an event

Welp, I though doing this was possible

InventoryTemplate.TextLabel.MouseEnter:Connect(StartInputConnection(InventoryTemplate));

Though, both are Local functions :thinking:

Here’s a bit more of the code;

function StartInputConnection(InventoryTemplate)
	Connections[InventoryTemplate][#Connections[InventoryTemplate] + 1] = UIS.InputBegan:Connect(function(Input,ended)
		if (ended) then
			return nil;
		end;
		if (Input.UserInputType == Enum.UserInputType.MouseButton1) then
			print("Grab!")
		end;
	end)
end

function EndInputConnections(InventoryTemplate)
	for i,v in pairs(Connections[InventoryTemplate]) do
		v:Disconnect();
	end;
end

local function CreateInstances(Data)
	for _,info in pairs(Data.Humans) do
		local InventoryTemplate = script.Parent.Templates.InventoryTemplate:Clone();
		local ParentTo = RealInventory.HumanSkills;
		InventoryTemplate.Parent = ParentTo;
		InventoryTemplate.TextLabel.Text = info.Name;
		Connections[InventoryTemplate] = {}
		InventoryTemplate.TextLabel.MouseEnter:Connect(StartInputConnection(InventoryTemplate));
		InventoryTemplate.TextLabel.MouseLeave:Connect(EndInputConnections(InventoryTemplate));
	end;
	for _,info in pairs(Data.Bacons) do
		local InventoryTemplate = script.Parent.Templates.InventoryTemplate:Clone();
		local ParentTo = RealInventory.BaconSkills;
		InventoryTemplate.Parent = ParentTo;
		InventoryTemplate.TextLabel.Text = info.Name;
		Connections[InventoryTemplate] = {}
		InventoryTemplate.TextLabel.MouseEnter:Connect(StartInputConnection(InventoryTemplate));
		InventoryTemplate.TextLabel.MouseLeave:Connect(EndInputConnections(InventoryTemplate));
	end;
end;

Yeah :slightly_smiling_face: , but Connections accept only a function type of value, because the connections run the function (with all of the parameters), so putting the function with a () in a connection will not consider it as function.
Do this instead:

InventoryTemplate.TextLabel.MouseEnter:Connect(function()--Create an anonymous function
	StartInputConnection(InventoryTemplate) --That runs the other function with the parameters
end)
InventoryTemplate.TextLabel.MouseLeave:Connect(function() --Create an anonymous function
	EndInputConnections(InventoryTemplate) --That runs the other function with the parameters
end)
2 Likes

Oh, sad, welp wasting memory in 2 functions extra -cries-

Yeah, sadly.

I am pretty sure that behaves like that since adding the (parameters) to the function runs it. So since nothing is being returned, its type is nil. And you can’t connect something to nil :thinking:.

Example:

local function testFunc(arg1)
    print("test")
end
someTypeOfEvent:Connect(
    testFunc(arg1) --It now runs and returns nil, so it's type is nil and not a function.
)
--Passed value is not a function, it is nil.