I have a couple different checkpoint systems that run off .touched and I’ve been noticing that when these systems get hit really hard as of recently, they seem to be Queueing rather than running Asynchronously.
Example, for folks unsure what I’m saying:
Script A runs .Touched
Script B runs .Touched
Script A fires right before Script B.
Script B’s code is faster, however, Script B does not resolve until Script A finishes Resolving.
In my actual case, we’re talking about 10-15 cars in-game, running a checkpoint system in each of them, which means that we’re talking 10-15 scripts queueing rather than 2, so the effect seems much more drastic as it appears it’s all lagging behind, to the point where everyone can stop & you can witness things resolving behind where people have stopped at.
So, is it particularly that the Touched event is queueing?
Or is something else the likely cause of this queueing?
List of other events/services in the script:
Color3
Getting/Setting Attributes
PhysicalProperties
If it is the case that Touched is the one queueing, is there a different event that I could use similarly to Touched [maybe Raycasting?] that would work asynchronously?
Don’t use raycasting, this would create even more lag (as I would think)
I’m pretty sure setting attributes contributes to lag, and maybe PhysicalProperties? I’m not sure.
Try optimizing your scripts as well as possible to avoid heavy lag.
Actually, I’m pretty sure Raycasts are more performant than .Touched however this has nothing really to do with performance and much more to do with what looks like queueing of my code across multiple scripts. A singular instance of the code is performant, but multiple is not.
Your fishing of [this] “contributes to lag” is not contributing to this post at all. Everything contributes to some form of lag, by virtue of everything takes bandwith to do. I’ve worked on this code over 6 years, minus exploring options other than .Touched, there isn’t much else to optimize.
Ok, sorry. I didn’t quite know if you had fully optimized your car.
Is the touched event in your checkpoint or in your car?
If it’s in your checkpoint, I would switch to raycasting.
If it’s in your car, I would switch the touched event to your checkpoint and check if the part that is touched is part of a car.