How to spawn hitboxes/parts every 0.1 seconds without delay or spawns extra hitboxes based on lag?

Hello,
I was testing with hitboxes today and I know how I could make simple 1 hitbox attacks. The problem is if I needed multiple hitboxes to be spawned after each other after a certain amount of time. For example the player threw 10 punches within 1 second, that would be a hitbox every 0.1 second. Would I use RunService (I would imagine not because I want to spawn a hitbox every 0.1 second and not every frame) or a loop with a wait(0.1)?

Example of what I want done:


Note: The red spheres are hitboxes.

If you want precision, use RunService.RenderStepped.
You did say it runs every frame, but you can use another variable like so:

local RunService = game:GetService("RunService")
local repeatInterval = .1
local t = 0
RunService.RenderStepped:Connect(function(step)
    t += step
    if t > repeatInterval then
        t -= repeatInterval
        -- do stuff
    end
end)
1 Like

Would this make it where if the step was .2 seconds long it would spawn 2 hitboxes to make up for lower FPS?

You could fix it by replacing the if statement with while t > repeatInterval do

What if it was a dash attack which spawned a hitbox at the attacker’s RootPart every frame? How would you make up for lag with that, if you just spawned the amount of hit boxes missed they would all be at the attacker’s RootPart instead of the skipped parts of the dash path.
Example:


How would you spawn those missed hitboxes where they need to be in the path of the dash?

Honestly you could use a repeat loop or a for loop and get the amount punches you want and time you want like so time/punches in my opinion using a for loop would be easier like so;

local punches = 10
local time = 1–second
for i = 1, punches, 1 do 
—spawn your parts
 wait(time/punches)
end 

If the hitboxes are being made on the server, then that’s just ping. Not much you can do about that

That wouldn’t compensate for lag, but nonetheless I appreciate your response.

Could I do anything about it if they were client-sided or still can’t do anything about that?

If it were client-sided there would be no visual lag, BUT you would be more vulnerable to exploits bc of the need to fire a remoteevent for collisions

You can use heartbeat for server but it will only account for the lag on the server and not on an individual client.