So what I’m trying to do is to make a really quick gun, but the max is 1bullet per renderstep. Is there any way to make it shoots out more bullets without changing the renderstep? Making it two bullets per renderstep isnt the choice.
Like in a minute a gun can only shoot 3600 bullets. Any how to increase the number?
As CodeNil said, you can’t make it “faster” than RenderStep. But you can simulate it faster by launching several bullets per RenderStep (or Hearbeat which is more reliable) and alternate their velocity and start point. Ie. shoot three bullets per RenderStep where each bullet is offset from one another forward by X distance.
You should only be using RenderStepped for rendering, as it fires before any render updates happen. You should be using either Stepped or Heartbeat. They both run parallel to the render updates, but Stepped fires before the physics update and Heartbeat fires after.
The answer here isn’t faster loops, it’s physically positioning the bullets to represent a faster frequency. Anything faster than one frame is practically meaningless, so if you want to fire 2 bullets per frame, put the first one further ahead than the second one.
You shouldn’t be using RenderStepped for something that isn’t graphical.
Otherwise, the gun would fire slower for people with a poor framerate.
Heartbeat is a consistent 60 fires per second.
Anyway, assuming that the gun fires at 10,000RPM or 167RPS, every Heartbeat you could have the gun chamber 2.8 rounds then fire off the math.floor of the number of chambered rounds.
So:
Frame 1: 2.8 rounds in chamber, fire 2
Frame 2: 3.6 rounds in chamber, fire 3
Frame 3: 3.4 rounds in chamber, fire 3
Frame 4: 3.2 rounds in chamber, fire 3
Frame 5: 3 rounds in chamber, fire 3
Frame 6: 2.8 rounds in chamber, fire 2
etc.
While it may sound like a bad solution to fire multiple shots at the same time, no one will notice when there’s 60 bursts a second.
Why would you wrap it in a spawn? The Lua VM in Roblox is singlethreaded, so only one thread can run at a time anyway. Aside from that, spawn postpones execution until the next frame, so this line of code causes all sorts of strange effects you may not notice straight away. I would just do shoot() instead of spawn(shoot).
PS: Heartbeat or Stepped is better here instead of RenderStepped, probably.
-- this method is very laggy
-- only recommended as last resort
local number = 10 -- the more, the faster (and laggier)
while true do
-- code
if math.random(0,number)==number then task.wait() end
end