Hello! I have a train and I move it with BodyVelocity by setting the velocity every 0.2 seconds in a while true do loop in a server script. The problem is that every train has 2 scripts and if there are 15 trains - that’s gonna be 30 scripts in total, so it will memory intensive and thus, the server will lag.
So, straight to my question. What is the best alternative to BodyVelocity that will not take so much memory and won’t be too hard to use?
BodyVelocity is a good method of moving models in your game, however perhaps you’re going around the scripts wrong.
Is it entirely necessary to update the velocity every 0.2 seconds?
Could you not create a module that handles all trains? For example, listen for a model being added to a folder and handle the train there.
Is it entirely necessary to update the velocity every 0.2 seconds?
Well, it is kind of necessary since I want the speed to go up smoothly and so, I have to wait in between the different speeds.
Could you not create a module that handles all trains? For example, listen for a model being added to a folder and handle the train there.
I was thinking of controlling all trains from 1 script but I heard that when a script gets a lot of requests, it can eventually timeout. (which I don’t know if it’s actually true)
In terms of speed moving up slowly, have you tried using the TweenService?
In terms of timing out, that isn’t an issue you need to worry about with scripts. One of the issues you will need to worry about is scheduling and making sure all your code is being executed. You should consider using coroutines to make sure everything’s running smoothly.
For reference and further help, consult the following articles and documentation:
I am not really experienced with tweening whole models and I don’t know how to calculate the distance to the next node and tween each carriage respectively.
In terms of timing out, that isn’t an issue you need to worry about with scripts. One of the issues you will need to worry about is scheduling and making sure all your code is being executed. You should consider using coroutines to make sure everything’s running smoothly.
I will consider this and will try doing that today. Thanks for the help!