Let's talk lag -- What causes it? How do we stop it?

For those coming by, this topic has been solved by many users in here. However some discussion does exist for specific sub-topics.

In particular, I want to note that @wow13524, @XxELECTROFUSIONxX, @greatgavin, and @Fifkee have some pretty informative replies!

I hope this post acts as a resource for those who need to optimize their code. If not, my upcoming community resource will help with that soon :slight_smile:

1 Like

Thanks so much, it’s super helpful :slight_smile:


@FieryEvent I will make a community resource soon on lag with examples of the tick usage, if you don’t mind waiting. In the meantime, I do have a lot of sensitive code I would rather not reveal.

The coroutine library of course, there’s nothing that can’t be accomplished with coroutines or bindables even due to their threading behavior that can through spawn.

Essentially fastSpawn, a function that would create a new thread since event listeners are called in a new thread (and show error information as well):

local function func(...) while true do wait() end end

local function fspawn(f)
   local b = Instance.new("BindableEvent")
   b.Event:Connect(f)
   b:Fire()
   b:Destroy()
end

fspawn(func)
wait(3)
print("prints")
coroutine.resume(
   coroutine.create(function() 
       error()
    end)
 ) --> no traceback for error

coroutine.wrap(error)("ERROR") --> error

-- both error
spawn(function() error() end)
fspawn(function() error() end)
1 Like