So my gun doesn't register the kill, any solution why?

Here’s my code:

And here’s what it is doing:

Ultimately I’m trying to check whether the Health of the player I’ve just killed is < or = 0 and if so just print something for now, however it’s registering AFTER I shoot another bullet at the dead target. Any solution or error with my code? Any help would be appreciated!

I don’t see any code that checks for the death of the target after damage has been done. That’s probably the problem.
image
You apply damage… but what’s next? The script just ends there.

image
It’s checking here, and it works but only works after I shoot the dead rig again.

The problem is that it’s not registering when it dies, only AFTER it dies and I shoot it again.

That’s exactly the problem I’m describing. It doesn’t check for the player’s health immediately after dealing damage, only before it. Once it deals damage, it does nothing until the next event.

To fix it, you need to move the check to the bottom of the script so that it always runs after the damage is dealt.

if player then
  if player.Humanoid.Health >= 0 and not player.IsDead.Value then
    ...
    player.Humanoid:TakeDamage(Stats[type].dmg) --deal damage first if it can
  end
  if player.Humanoid.Health <= 0 then --NO ELSEIF STATEMENT
    player.IsDead.Value = true --check for death AFTER dealing damage
    ...
  end
end

Also, there are some pretty terrible coding practices in your script.

  • It doesn’t make any sense to be using :FindFirstChild if you’re going to directly index the result. :FindFirstChild is only used when the child’s immediate presence cannot be guaranteed, and you’re treating it as if it’s always guaranteed. You should just use regular dot operators in this case.
  • You didn’t store Humanoid somewhere either; it’s extremely redundant to call :FindFirstChild over and over again.
  • What is up with that yanderedev style coding on the client script? You should never have to structure your if-else statement into a long cycle like that. Use loops or short-circuit logic instead if you can.
1 Like

Gotchyu, thank you for the criticism I’ll try to implement that into my everyday coding for now on, I’ll try that now and see if it works.

It works, I appreciate it and thank you for the advice. :pray: