Which is better. using a loop. or an event

I have a mouse.Moved event. that firesserver to change the mouse.target and .hit values i have inside the player. i was wondering if it’d be better to have loop do it than an event.

which would be better for performance.

1 Like

Yeah events are more efficient.

1 Like

Events are better for two main reasons, they are more resource friendly since they don’t constanly run their inner code, only when something happens, and they don’t yield unlike loops, you can also :Diconnect() afterwards.

Another example would be a loop checking if a certain property has changed vs the .Changed event. Obviously obviously .Changed is better.

7 Likes

As demonstrated by your solution, Starmaq, events are far better than loops when it comes to value checking accuracy and performance cost though I’d really like to know if a “GetPropertyChangedSignal” event (Position of the player’s character Root part changing constantly ) to let an NPC follower know where to move towards the player would still be more effective than a half or quarter second loop. (Which I’m currently using right now for this case only)

I’m also sorry if this post was a little late- I know that events are more effective generally but I was stuck on my case here and couldn’t find a clear answer for my case anywhere. :confused: