I’ve been trying to improve various portions of code I’ve wrote, trying to use Module Scripts to reduce the amount of spaghetti code but this atrocious wait function I tried to use simply refuses to work:
function functions.wait(n)
local elapsed = 0
if n == nil then n = 0 end
repeat
elapsed = elapsed + game:GetService("RunService").Heartbeat:Wait() --Why doesn't this work!?
until elapsed >= n
return elapsed
end
Every time a script calls that function from the module script, it returns an error like this:
ServerScriptService.Functions:12: attempt to compare table and number
I’ve tried using other methods such as tick() and os.clock() and they all have the same result.
The function works 100% when it isn’t in the module script however which is annoying and not what I want.
How am I supposed to fix this without copying the function to every single server script individually.