So basically i have this viewmodel gun script, and whenever you get hit by the bullet you take damage, eveyrhting is fine, until the player you shot dies. If you continue to shoot the corpse it still runs the function because the players health is below 0. I tried using Humanoid.Died but that just made the function fire as many times as you shot the player(ex. I shoot player 3 times, function fires 3 times.) How can I fix this?
function TakeDamage(Player, PlayerDamaged, Damage, BodyPart)
if BodyPart.Name ~= "Head" and PlayerDamaged.Humanoid.Health > 0 then
PlayerDamaged.Humanoid:TakeDamage(Damage)
print(Player.Name .. " hit " .. PlayerDamaged.Name .. " in the " .. BodyPart.Name .. " an dealt " .. Damage .. " damage.")
elseif BodyPart.Name == "Head" and PlayerDamaged.Humanoid.Health > 0 then
PlayerDamaged.Humanoid:TakeDamage(Damage * 2)
print(Player.Name .. " hit " .. PlayerDamaged.Name .. " in
the " .. BodyPart.Name .. " an dealt " .. Damage * 2 .. " damage.")
end
if PlayerDamaged.Humanoid.Health <= 0 then
Player.leaderstats.KOs.Value = Player.leaderstats.KOs.Value + 1
warn(Player.Name .. " killed " .. PlayerDamaged.Name .. ".")
game.ReplicatedStorage.Notification:FireClient(Player, PlayerDamaged)
end
end

2 comments
Keep in mind that you don't fire functions, you call them.
Basically you need to tell the script if the player is dead