I’m getting a very strange error stating that I cannot yield in a thread, but why is that? The error is pointing to task.wait() and I cannot figure out what’s wrong with it.
function Server:Get(name: string): any -- Yields
local calls = 0
-- Wait for data to be created
repeat
task.wait()
-- Prevent infinite yield
calls += 1
if calls > 100000 then
error("Tried to retrieve a stream but reached the wait limit, did you forget to create the stream?")
end
until Streams[name].DataWithInterface ~= nil
-- Return the data
return Streams[name].DataWithInterface
end
Someone else told me that metatables cannot yield at any point, which is what happened in my case, I just simply had to wrap a call inside a metatable in a task.spawn() like you suggested. Thanks!