So basically I want to pass an instance into a ModuleScript function that is nil at first and that won’t be nil after some time. Unfortunately ModuleScript reads the nil instance, that is nil at first, as nil all the time instead of reading it as nil for few seconds, example:
require(Module).Yield(game:GetService("ServerStorage"):FindFirstChild("ThingThatIsNilAtFirst"))
ModuleScript reads it as nil instead of the path even when instance becomes not nil.
How can I fix it?
For more information please ask down below in reply (the post is a little chaotic).
1 Like
Did you define your functions with the :
operator?
I did with . operator. What is the difference between : and .? I does usually use . and it works fine.
local t = {}
function t.dot(...)
print(...)
end
function t:colon(...)
print(..., ...== t) --// get the first value of tuple
end
Wait the thing does not work (oof). Here is my Module:
local YieldModule = {}
function YieldModule:Yield(yInstance)
print(yInstance)
if not yInstance then
print("before")
repeat print("repeating") wait(0.07) until yInstance
print("after")
end
print("done y")
return true
end
function YieldModule:YieldStoppable(yInstance, rInstance)
if not yInstance then
repeat wait(0.07) until yInstance or not rInstance
end
return true
end
return YieldModule
The Yield function keeps printing ‘repeating’. It means that the script still sees the value as nil.
Also can you explain the difference between colon and dot since I did not understand your last post well?
By using the :
operator, the first value passed will be overridden to the table it self.
Also, if whatever passed is nil, it will always be nil, there is no need to wait for it.
Okay but
when you do repeat wait(0.7) until game:GetService("ServerStorage"):FindFirstChild("Thing")
it will yield until Thing would not be nil. I wanted to recreate the same thing but with ModuleScript. Unfortunately it is always nil. Do you know any way of doing that (I know one method but it is not very good and 60% it won’t work)?
You shouldn’t busy-wait anyways. You should always do something right after it happened.
If you don’t like long scripts put together, then you should instead try to use waitforchild
WaitForChild can throw a warning. And that is a problem here.
I found out a solution: instead of passing a nil object, you can pass an existing instance and a string of the thing that I used FindFirstChild on previously. Here is an example:
local instance = game:GetService("ServerStorage")
local str = "NilObject"
local path = instance:FindFirstChild(str)
1 Like