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

Function connection problems?

Asked by
emite1000 335 Moderation Voter
10 years ago

When I added a small function to my script to check if the Mouse's target was an object, it started giving me an error: Attempt to connect failed: Passed value is not a function at line 4.

script.Parent.Equipped:connect(function(mouse)
    mouse.Button1Down:connect(function()
        if mouse.Target == nil then
        else mouse.Button1Down:connect(Check)
        end
        function Check()
--the rest of script goes down here. It's been working fine.

I'm not sure what it means that the value is not a function. I have a guess that it might have to do with me use mouse.Button1Down twice, but I'm not sure (also, I didn't know what other Event to put there).

1 answer

Log in to vote
0
Answered by 10 years ago

You made a little confusion.

script.Parent.Equipped:connect(function(mouse)
    mouse.Button1Down:connect(function()
        if mouse.Target == nil then
        else mouse.Button1Down:connect(Check) -- You shoulden't be calling it by event. You can't force the MOUSE to connect it.
        end
        function Check() -- make this come first :P
--the rest of script goes down here. It's been working fine.

The ATTEMP TO CONNECT FAILED means it couldn't connect to function since the EVENT returns false and not true like it should return.

Let's take a look at Events: They are read-only, wich means you cant edit them. You can only read them and use them, but you can't edit them. In this case, you tried to edit an event.

Just replace the 'mouse.Button1Down:connect(Check)' with 'Check()'.

You could also change the 'if mouse.Target == nil then', that part you make the code 'NIL' inside statement. You could just replace to 'if mouse.Target ~= nil then', wich means it isn't 'NIL'.

function Check()
-- idk wats ur code for this
end

script.Parent.Equipped:connect(function(mouse)
    mouse.Button1Down:connect(function()
        if mouse.Target ~= nil then Check() else return end

Hope this helps! If it doesn't, tell me what appears on output. Thanks, marcoantoniosantos3

0
No no no. If the Target does equal nil, I want it to end. If it DOESN'T equal nil, I want it to run the function. emite1000 335 — 10y
0
okay, try now with updated post marcoantoniosantos3 200 — 10y
0
Output is "attempt to call global 'Check' (a nil value)" at line 4. I think it's because you're not connecting to Check(), you're just stating "Check()". emite1000 335 — 10y
0
try making function Check() before the event :P It will work marcoantoniosantos3 200 — 10y
0
(sorry about late-ish response). But no, it doesn't work because now the word "mouse" in the function at line 2 doesn't work (since it isn't defined until later). emite1000 335 — 10y
Ad

Answer this question