Error "Attempt to connect failed: Passed value is not a function"

I keep getting this error and I don’t understand why. Can someone help me to fix this? Thanks.

function FindLevel()
	for i, d in pairs(script.Parent:GetDescendants("CurrentLevel")) do
		if d.Name == "CurrentLevel" then
			for i, upg in pairs(upgrades) do
				if d.Name == "Backpack" then
					print(d.Name, upg.Name)
				end
				if d.Parent.Name == upg.Name then
					local label = d
					label.Text = string.gsub(label.Text, "_", upg.Value)
				end
			end
		end
	end
end

FindLevel()

for i, upg in pairs(upgrades) do
	upg:GetPropertyChangedSignal("Value"):Connect(FindLevel())
end
1 Like

Get rid of the parantheses in your connection.
This happens because a function is essentially just a variable with a code block attached to it, and when you do Connect(FindLevel()) you are connecting to the value returned by FindLevel : nil.

1 Like

Hey thanks it worked for me!!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.