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

Delay function error with parameters?

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

✓ Accepted answer

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!

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