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

Delay function error with parameters?

Asked by 6 years ago
if inputObject.KeyCode == Enum.KeyCode.J then 
    delay(0,Function) -- Works
    wait()
    delay(0,Function(Parameter) ) -- Err0r
end 

So I noticed that I needed my functions to run parrell with each other so I discovered the delay function, however my functions require one or more paramters at least when they'e being called.

I get the error "delay function requires 2 arguements" or something similar, even though im clearly using two arguments when calling it.

Any help explaing this would be great ^^

P.S I noticed that when I call the delay function like this (at the end of my code, with parameters) the code will *still *run, then throw an error and break the code.

1 answer

Log in to vote
1
Answered by 6 years ago

Unless your function returns a function, this won't work. Your code is like

local returnValue = Function(Parameter)
delay(0, returnValue)

Since your function does not return a function, you are doing

delay(0, nil)

which is invalid.

As a solution, you'd need

delay(0, function()
    Function(Parameter)
end)

Hope this helps!

Ad

Answer this question