Hello, I have run into a problem with my code. I want to calculate the damage of a weapon without knowing the actual damage.
Here’s the script:
local dps = humanoid.MaxHealth - currentHealth
How would I go about determaining the damage of the weapon? The script above returns the damage first but then it doesn’t return the damage value, it returns damage*2.If you have any suggestions, please feel free to post.
im not sure but i would do:
local lastHealth = humanoid.Health
if currentHealth < lastHealth then
local dps = lastHealth - currentHealth
print(dps) -- This should be how much damage the humanoid took
lastHealth = currentHealth
Try that, and reply to me if it doesn’t work
If you don’t know the Damage that the Weapon does, you can’t damage the Player, kind of obvious…
But if you talk about NOT putting a Value inside the Weapon called “Damage”, you can use InvokeServer to get info or just make a ModuleScript with all weapons info
I really don’t know what you want to do, if you explain better I can answer you better.
If you don’t know what the OP is asking, don’t answer, kind of obvious…
If you read the question closely, then you would understand they are basically trying to determine the difference between the player’s new health between the player’s old health, giving them said damage dealt by the weapon
local previousHealth = humanoid.Health -- save current health at the start.
if newHealth < previousHealth then -- if health decreased
local damageDealt = previousHealth - newHealth -- get damage
-- TODO: do something with 'damageDealt'
-- This line means they got healed instead.
-- Note: this should be applied last and outside all health checking.
previousHealth = newHealth -- updates previousHealth for next calculation.
Similar to what the first reply said but moved the ‘lastHealth’ outside the if statement so it works if they got healed as well.
Oh, I can’t believe I forgot that lol. Good catch