Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago

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

Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

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

Ad

Answer this question