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

Connect error despite functions being defined?

Asked by 7 years ago

Attempt to connect failed: Passed value is not a function

Always occurs on my script.

function OnUpdate()
    if updating==true then
        warn("Already updating.")
    elseif updating==false then
        print("Updating...")
        updating = true
        local name = vars.name.Value
        collectNew(name)
        if abort==true then
            warn("Update aborted.")
            abortFlush()
            abort=false
        elseif abort==false then
            wait(5)
            test()
            flush()
        end
        updating = false
    end
end

vars.name.Changed:Connect(OnUpdate())

vars is a variable leading to a folder, name is a string value. collectNew gathers information through a proxy on the Roblox API, with a little snippet making sure the passed value is not blank or nil.

function collectNew(name)
    if name then
        if vars.name.Value=="" then
            warn("Name is empty, aborting...")
            abort = true
            return true
        else
            print("Name check cleared.")
        end

flush() sends the retrieved information to string values in the var folder and then clears the information,

function flush()
    vars.outputI.Value = Group
    vars.outputII.Value = ID
    vars.outputIII.Value = Info
    wait()
    Group = ""
    ID = ""
    Info = ""
end

whereas abortFlush() clears the information without sending it

function abortFlush()
    Group = ""
    ID = ""
    Info = ""
end

the abort functions are in place because OnUpdate() fires as soon as the place starts, regardless of whether or not the name string is changed.

2 answers

Log in to vote
1
Answered by 7 years ago

By passing onUpdate() you are actually firing the function and passing what it returns. You should write onUpdate to pass the function without firing it.

0
Thank you (and WingedHorizen) for the answers! It (seems to, i can't tell completely since roblox is down) works fine now. Yognuaght0me 2 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

I may be mistaken here, and I am not a very experienced programmer, but isn't the line,

vars.name.Changed:Connect(OnUpdate())

supposed to be without the parentheses?

vars.name.Changed:Connect(OnUpdate)
0
We posted answers almost at the same time :D Look at my answer for explaination. Programical 653 — 7y
0
You should look at Programical's response below. It's a little more detailed than my response. WingedHorizen201 124 — 7y
0
Jep without the parentheses stefdejup1 0 — 7y

Answer this question