Can module scripts make the script wait for modulescript

I’m currently working on a
Property:Wait() with Argument module, and I was wondering, if modulescripts can make a script wait for the modulescript , if possible please tell how.


Yes, you can wait within a module’s portions (you can probably write task.wait() before you return and see some kind of yielding, I haven’t tested this).

Let me paint a bigger picture of what modules actually are so that you can understand. If you’d like to develop further understanding after reading this, see packages.

A ModuleScript will only run one time per code environment, and it is a source container, that is to say that when you require a module, you are receiving what it returns and that is how it will exist for that specific environment. You are not indexing “out of the module”, because once you have required it the code already exists.

If the code inside your module contains yielding, then your thread will yield accordingly. Writing Module:Wait() is pointless in Lua. Packages are code containers, not a property to yield for. You should be requiring your module & then yielding within it how you would like to.

I.e; there is no reason for require(ModuleScript):Wait(), it is syntactically incorrect and non-sensical. However; some function that exists within your module’s return can yield, and then yield your normal environment because it then exists there.

1 Like

if it wasn’t clear, I’m making a modulescript that adds arguments to property:Wait() not wait for modulescript, but I want the script to stop and wait for modulescript and resume when an argument is returned.

Here’s an example :


Output :

What I want
Output :


no, i want the script to wait for the module


--this will print in 5 seconds
local module = {}

function module:Wait(time)
      return task.wait(time or 0)

return module
local module = require(...)


and what if i want to return a value like a property?

You don’t need to return the task.wait() just return whatever you want the script is still going to yield

ok gonna try this (30 ch arsss)

One thing to note is if you want to change what the function returns you can but make sure to keep the yield there.

ok one question,
will it also wait if we do this (another wait)

function waitwithargument:WaitForProperty(property)
	return property

:Wait() is used to wait for Events to happen so if you pass something like BasePart then it will error because you can only wait for Events and I don’t really know why would you need to use ModuleScript function for that.

because im making a module that adds arguments to the :Wait() since you cant do that normally

it worked anyway , thanks (30 ch ars)

No you can’t really do it that way I know what are you aiming for but it’s not possible.

i said it works it was possible