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
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 ?
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.
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 , 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)
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 .
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.