I am currently running into a bug with Maid, where I am trying to add a local function and I run into a warning where it said the Task cannot be false or nil.
local function testFunc()
end
Maid:GiveTask(testFunc())
I am currently running into a bug with Maid, where I am trying to add a local function and I run into a warning where it said the Task cannot be false or nil.
local function testFunc()
end
Maid:GiveTask(testFunc())
Make sure there is something in Replicated storage named Maid edit this script to work with your system try this:
-- Require the Maid module (assuming it's stored under ReplicatedStorage)
local Maid = require(game:GetService("ReplicatedStorage"):WaitForChild("Maid"))
-- Define your local function
local function testFunc()
print("Executing testFunc")
-- Function logic goes here
end
-- Create a Maid object to manage tasks
local maid = Maid.new()
-- Add testFunc to the Maid for cleanup
maid:GiveTask(testFunc)
-- Example of triggering testFunc
testFunc()
-- When you want to clean up (e.g., when the script stops running)
maid:Destroy()--remove this if you want the script not to be deleted
You’re passing the return of the function to the maid. Instead of passing testFunc() as an argument you should be passing testFunc instead.
You aren’t passing in the function, instead you’re passing in its response. You aren’t returning anything so it returns the default value which is nil. So basically you’re passing nil inside the GiveTask function instead of your function, and that’s why the error occurs.
Instead do: Maid:GiveTask(testFunc)
I get “Attempt to get length of a nil value” instead, and “e” doesn’t print in output.
function testFunc()
print("e")
end
Maid:GiveTask(testFunc)
read my other reply (thirty chrss)
You’re not giving enough context for us to understand your problem. You need to show us where exactly you are creating the maid class and how you’re creating it. You should include code that is relevant to your problem so others can diagnose and fix the issue properly. You should also tell us which Maid module you are using, as there are multiple.
Here is the snippet of code that maid uses for the specific method you’re having trouble with:
function Maid:GiveTask(task)
if not task then
error("Task cannot be false or nil", 2)
end
local taskId = #self._tasks+1
self[taskId] = task
if type(task) == "table" and (not task.Destroy) then
warn("[Maid.GiveTask] - Gave table task without .Destroy\n\n" .. debug.traceback())
end
return taskId
end
(source)
In Quenty’s maid module, GiveTask requires you to give a table with a Destroy method attached to it. A function does not have Destroy, and it is not a table. It’s already not the correct argument for this method.
Not what that code is saying at all, it’s ensuring that in the event that a table IS passed, it has proper methods for garbage collection.
Instead, it’s very likely that OP (@SakurajimaStan) did not Instantiate a new Maid.
Calling the base class (the base return from the module) will not work for near any Maid module currently released, as almost all of them require you to create a new Maid with Maid.new().
My apologies if I wasn’t clear. I understood that improper instantiation might be an issue. I said:
I only specified that a function isn’t the correct argument for further clarity. There will still be an issue passing a function to GiveTask even after instantiation is done correctly.
I send my apologies back if I myself was not clear enough, GiveTask expects the (rough, I did not ensure this type inference is actually functionally sound,) equivalent to this typedef:
export type Task = (...any?) -> unknown | {Destroy: (...any?) -> unknown};
It accepts either a
or a
Edit: And that’s not even entirely correct either, don’t know how I forgot this.
This is closer
export type Task = (...any?) -> unknown | {Destroy: (...any?) -> unknown} | RBXScriptConnection;
Ah, sorry, I see the problem with my statement now. I overlooked the fact that a table wasn’t required but a disconnect method must be provided if a table were to be passed. Thanks for the correction! I will edit my post.
Are you just directly doing require(path.to.Maid):GiveTask()?
:GiveTask() expects a maid “instance”, which you can make by doing local maid = require(path.to.Maid).new()
and then you can run :GiveTask() on that made instance, so in all, it shoud look like this:
local maidModule = require(path.to.Maid)
local maid = maidModule.new()
maid:GiveTask(your-local-function)