A Better wait() Technique?

Ok so in simple terms, I have a function for firing bullets in an FPS game. The function doesn’t yield aside from a simple wait(60/RPM). It recurs if conditions are met for full-auto fire.

The issue present, is as frames drop, the fire rate slows down. I’ve made note in the past, that the wait() service is affected directly by memory usage. I can’t use render-step because that’s directly linked to framerate and won’t give me the constant rate of fire I need.

Is there something better than the wait() service that I can use to achieve a constant yield time, less than 1 second, regardless of user framerate and memory usage?

Ok so I’ve coded a function that seems to work well enough, but if anyone has a more elegant solution, I’d love to hear about it:

(It’s important to note that I already log and write average framerate to a variable)


This won’t give you a constant yield time, but the best method to make this less of an issue is to use the return value of wait()

local deltaTime = wait()

(RunService Events also have deltaTime)

1 Like

Here’s something else I’ve found about my function above, because it rounds down I can’t say it’s ‘accurate’ however because I have alot of weapons with firerates above 800 RPM, the function performs infinitely better than using wait() simply because it can handle yields less than 0.1 seconds. Even at 60 FPS theres a noticeable difference between my function and wait()

Are you managing the firing of bullets on the client? From the looks of it you are. If yes, wouldn’t a better solution to this just be handling it via the server?

Clever, you’ve actually worked with a similar system back on Fray 1. The bullets are fired on the client to properly manage sound, particles, animations, and camera movement. Only the hit detection is managed by the server. I’d also like to point out, that the server can only operate at half the speed of the client, so it would be more consistent times yes, but it wouldn’t be fast enough. I’ve created a really fast yielding function here that solves my issue completely: Outdated {view new post linked below}

1 Like

What happened to Runservice.Heartbeat:Connect()?
Is that tied to the framerate too? Cause last I remember it was only a set time…