Alright so I’m scripting a car and I needed a way of returning a value and update engine sound, my solution was to add a while wait() do loop but I stumbled upon a problem that It can cause lag, but I don’t know in this case because it updates 2 stuff.
Someone said I had to use fireallclients and update them from the client but is that really the case?
This loop shouldn’t be an issue, however, you should use task.wait() instead.
an empty task.wait() is equal to RunService.Hearbeat:Wait().
More information can be found here: Task.wait(n) vs wait(n)
Just incase you were confused, I will explain the 2 major things I brought up.
Coroutines create a thread, basically like a script. Running anything in a corountine would be run like if it was on a different script. Which is useful for multi-tasking scripts.
RunService.HeartBeat fires every frame after the physic simulation has been done. If you want to have it fire before the physic simulation then I suggest RunService.Stepped.