using all the trig probably isn’t neccesary, and it’s probably slower too, using the dot product would be better for calculating the LocalLinearVelocity
I am unsure if using parallel lua in this case is actually faster than running the code in serial. Parallel lua introduces a good amount of overhead, and your script might be faster in serial because of that. Parallel lua is mainly useful when doing a lot of WorldRoots, raycasts, or like giant tables you are serializing/deserializing.
One other thing to note is that changing the properties of objects (in your case RootJoint.C0) is surprisingly not that fast and that operation alone could be slower than the math you are doing (though I would have to test it be sure).
This will give you how many seconds it takes to run the code
To test it in serial, replace the ConnectParallel with Connect, and remove the task.sync()
How many instances of that script are you running?
I realized the code I provided to check how much time it takes doesn’t really work when having multiple instances of the code running (it will print multiple times). To effectively measure how much time it takes you’d need to run all the instances from a for loop (in serial) or in parallel have some sort of callback when all the parallel tasks are done. It’s a lot easier to just look in the micro profiler
If there is only 1 instances of that script (and 1 actor) then parallel lua isn’t effective since it can only use 1 cpu thread, unless you have other code that is also running under an actor
I’m mostly separating a bunch of code between actors; one actor usually has 5-7 scripts. Also, consider the fact that the more players in the game, the more code of such will be here