how to detect when you get damaged and how much damage you took plssss
hi thanks thx hi
ermmmmmmmmm thats all I want to know
local localPlayer = game.Players.LocalPlayer
local char = localPlayer.Character
char.Humanoid.Health.HealthChanged:Connect(function()
if char.Humanoid.Health < 100 then
- - whatever you want to do here
ummmmmmmmmm does that function return amount of damage taken? it ok
Did you test it, did it work. Sorry if it doesnât I mightâve used the wrong event
ermmmmm it says DamageDealt is not a valid member of humanoid im just tested it
for some reason the code below only works when the character dies (im tested it by slowly using :TakeDamage
Another edit, let me know if it works
Sorry, just changed the operator
Another edit!
sorry it took a while but it still has the same problem
I get an error saying attempt to index number with âhealthchangedâ
Not a very efficient way to do it, but you could use a formula to calculate it.
You could use this to calculate the damage taken:
local damageTaken = (char.Humanoid.MaxHealth - char.Humanoid.Health)
Itâs Health.Changed! Iâm so sorry, Iâm losing it
ok im get error attempt to index number with âChangedâ
Try this code:
local Players = game:GetService("Players")
local LPlayer = Players.LocalPlayer
local character = game.Workspace:WaitForChild(LPlayer.Name) or LPlayer.Character or LPlayer.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
wait(1)
Humanoid.Health.HealthChanged:Connect(function(health)
if Humaoind.Health < 100 then
- - whatever you want to do here
Full script would look like this:
local Players = game:GetSerivce("Players")
local localPlayer = Players.LocalPlayer
local char = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if humanoid.Health < 100 then
local damageTaken = (humanoid.MaxHealth - humanoid.Health)
--Whatever you want to run goes here
end
end)
for some reason this only runs the code below when the character diesss (im teseted this using :TakeDamage())
this me trying it and it nottee work
Why canât you determine the damage taken from the script that takes the damage? âŚ
umm im making a game where multiple things attack me!!! (pvp game) and im too lazy to add that to all characterr so im ask how to check when damaged within the character im using
Instead of â<â it should be â<=â otherwise this script wonât work.
local Players = game:GetSerivce("Players")
local localPlayer = Players.LocalPlayer
local char = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if humanoid.Health <= 99 then
local damageTaken = (humanoid.MaxHealth - humanoid.Health)
--Whatever you want to run goes here
end
end)