How do i loop through code at a certain speed?

i am making a bulletdrop in my gun system by making points on a curve as time goes on for the projectile. now that i’ve done that i need to make a raycast inbetween two points as it updates.

i was thinking ok since the first point starts at the head then connect a raycast once the second point is made which is based on time. im doing this while using renderstepped. now there’s a problem with this. the client can lag like 1 fps meaning the bullet would be a further distance ahead from lets say the second point. my code would then cast a ray from the last point which is 2 and to the 3rd one which is far away because the client is lagging 1fps. causing a problem. here i will make a picture of what i mean.

as you can see here the trajectory on the bottom is correct since its updating 60 times per second but if its running really bad fps like the top or has varied frames it will cause inconsistencies and cause rays that are not correct length and someone could probably use this as an exploit to have sorta hitscan bullets with no bulletdrop.

i could solve this problem if i can find a way to loop through this code at a constant amount thats not based on how many frames the client is running at.

i cant use wait() and a while loop because wait only goes up to 1/30 of a second which is 30 times a second and i dont want that. i want a loop that runs the code every 1/60 of a second. renderstepped cant do that and while loop with wait() cant either.

so if theres a way i can update every 60 seconds consistently independent of the clients frames please tell me.

Can you try doing the bullet drop at the server? The server does stuff independently from the client so yeah.

no its calculated on the client because if i do what you just said it will kill the server.

i tried it already. and the server is not meant to handle repetitive tasks like this so its going to appear laggy, delayed and choppy. what im doing is sending info to the server from the client then the server sends that info to every client so the clients can calculate the projectiles so it can be smooth.


you could use deltatime to calculate what distance it should’ve been

Maybe you can use Fastcast for this. People have already tried using raycasts for shooting projectiles before.

You can use Stepped/Heartbeat/RenderStepped with a given delay per frame (to make it skip every other frame for example).