Need help to make code more reliable and clean

(before i begin, No, I’m not looking for anyone to write entire scripts for me, i know how to script, just need help figuring things out)

Currently working on a combat game.

I wanted to make a damage indicator system, Everytime you damage someone, it shows text with how much damage you did.
I didn’t want to do this from the tool that damages other players, Since everyone would see the text then (didn’t want to use remote events to tell the client either)
So i just made a local script that checks through every player whenever they get damaged, and see if they are the one who did it, This works fine, But i feel like its not the best approach.

Along with this, I can’t detect deaths properly, With my killfeed system, it doesn’t always show who died (for whatever reason)
And when i try to make the damage indicator detect deaths via Humanoid.Died, Its really delayed (i know the reason)

So i tried to make it check if the player you damaged is now dead, Great, Right? No, because if you hit the person while they are dead, It says you killed them again (really annoying)

And for an infection gamemode im trying to make, It also goes through EVERY player, Probably not good either since the server constantly watches characters incase they die or get damaged.

Back to the damage indicator, I really don’t know what to do for this anymore, I just want it to check which ever humanoid you hurt, Not just players.

This is really blocking further development of my game, Any help is appreciated.


Anytime you add something that you know has a Humanoid in it whose damage you want to track, connect Humanoid:GetPropertyChangedSignal(“Health”). You can connect this to whatever you want but probably you need to do it in twice: Once in a local script to display the damage indicators (so they are instant and local to the player that caused them), and once in a server script which runs your killfeed. That script can ignore any messages for humanoids that were already reported dead.


As i stated in the post, I’d prefer for it to somehow check whatever humanoid you damaged without having to make tons of connections.

The way I’m detecting when a humanoid is damaged is not the issue, I just want a better way to detect when any humanoid in the game is damaged, Without having to constantly connect stuff for it.
My current code is such a mess, It always checks when a player is added, and then waits for their character, And has more code that checks through all current players, But i have to have this large chunk of code every single time i want to detect when someone is damaged.

1 Like

You want to use connections for this, because then your code only runs when it needs to. When the target of the connection (the Humanoid) is removed the connection is automatically removed. This is much much faster than checking every humanoid in the server rapidly. I don’t know why you don’t want to use them, so tell me what you think would be bad about using connections?

1 Like

Honestly, I’m not sure, i just felt like the way i was always doing it was a bad way, It works fine, I just needed to know if there was maybe a better solution of some sorts.

I think the way damage is shown is good, But i keep having problems with detecting death, What i first tried, Was when someone dies, It disconnects the damaged event (checking for if the health is 0 or less) But i was having issues with that too.

i think another problem lies with the fact that im never sure of my code, So i always feel like the code is better if someone else tells me its fine, So thank you for that.

1 Like

You can make your killfeed script start ignoring messages from a Humanoid that has already sent a message saying its health is zero; then start listening again when you spawn that player / npc again.