Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is it possible to use the connect function in another function?

I ask this because I have been getting the error 'Attempt to connect failed: Passed value is not a function.' It doesn't give me which line the error occurs so I don't what I have done wrong. The script for reference:

local Mouse

function onClick()
 	local animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Animation)
	animation:Play()
end

function onEquip(a)
	if Mouse ~= nil then
	Mouse = a
	Mouse.Button1Down:connect(onClick())
	end
end

script.Parent.Equipped:connect(onEquip())

1 answer

✓ Accepted answer

onEquip() is what you do when you want to call the function. It's not the function itself. Replace with:

script.Parent.Equipped:connect(onEquip)

You have the same problem on line 11

This discussion is preserved as it was. New answers, comments, and votes are closed.