Mathing a value increment in a duration

Ok so I have this system I’ve created and it’s late and I’m drawing a complete blank on how to calculate this using the correct equation.

Using these two values, the goal is to take the duration, then take how much damage is supposed to occur, and then compile it into increments of 1 damage. For example, if the damage where to be 10, and the time was 10, it would do 1 damage per second for 10 seconds.

I feel like this is way simpler than I’m thinking it to be, but I just cannot do math right now.

local Damage = configuration.stingDamage
local Duration = configuration.stingDuration

…You can just divide the damage value by duration value and do a loop

-- 0.1 second precision
for i = 1, Duration * 10 do
humanoid:TakeDamage(Damage / Duration / 10)
task.wait(0.1)

-- 1 second precision
for i = 1, Duration do
humanoid:TakeDamage(Damage / Duration)
task.wait(1)

Wait, what do you mean by

1 Like

I mean like, for example my example of 10 seconds it would do 1 damage each second to 10 damage, which would be 10 increments of 10, i want to calculate the time so that it always does 1 damage, but it would do it in the duration evenly distributed.

so, if it were 20 damage instead of 10, it would do 1 damage every .5 seconds. Does that make sense?

1 Like

If the damage is too high and duration is too low, task.wait() limits (1 frame or ~0.015 seconds) might be broken and create very visible disruptions
The seconds formula for each 1 damage is 1 / (Duration / Damage)
This will work in condition that the seconds for each damage isn’t less than the length of 1 frame (damage will be rounded, for loops can’t handle decimals)

for i = 1, math.round(Damage) do
humanoid:TakeDamage(1)
task.wait(1 / (Duration / Damage))
end

Doesn’t seem to be giving the correct result.

The first print is the result of the task.wait equation. The second, is the print of the duration and damage.

image

Since the duration is 3, and the damage is also 3, it should be doing 1 damage/sec for 3 seconds.

I made a typo in the formula and fixed it, read my post again

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.