How would I go about determining the damage from a weapon

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:

humanoid.HealthChanged:Connect(function(currentHealth)
	local dps = humanoid.MaxHealth - currentHealth

  print(dps)
end)

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

humanoid.HealthChanged:Connect(function(currentHealth)
	
 if currentHealth < lastHealth then
   local dps = lastHealth - currentHealth
   print(dps) -- This should be how much damage the humanoid took
   lastHealth = currentHealth
 end

end)
1 Like

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.

1 Like

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

1 Like
local previousHealth = humanoid.Health -- save current health at the start.

humanoid.HealthChanged:Connect(function(newHealth)
	if newHealth < previousHealth then -- if health decreased
		local damageDealt = previousHealth - newHealth -- get damage
		-- TODO: do something with 'damageDealt'
	else
		-- This line means they got healed instead.
	end
	-- Note: this should be applied last and outside all health checking.
	previousHealth = newHealth -- updates previousHealth for next calculation.
end)

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