Currently i have a damage indication system which has the client fire a remote event when the clients humanoid takes damage
Code:
local Player = game.Players.LocalPlayer
local DamageEvent = game.ReplicatedStorage.DamageIndicator
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local LastHealth = Humanoid.MaxHealth
Humanoid.HealthChanged:Connect(function(Health)
if LastHealth > Health then
local NegatedHealth = LastHealth - Health
LastHealth = Health
DamageEvent:FireServer(NegatedHealth)
end
end)
and then on the server its pretty simple just a billboard gui. But i thought about it and what if i have many people taking damage at the same time this event will go off many times and it could be bad. Anyway to improve it?
Have your server listen for when the health changes instead of the client. The way you currently have it set up is exploitable (i.e. they change their health locally really fast). Then send a remote to the clients from the server saying that this player took damage.
Have you tried respawning and seeing if it still works? If it doesn’t then your code is not programmed to handle when players respawn. You could try to throw the local script side into PlayerGui and set PlayerGui.ResetOnSpawn to true, but I humbly ask that you don’t do that lol.
There are definitely downsides like offloading the performance to the server, but that performance dip is negligent (so, probably not even a real downside).
There’s a third route you can take, and it’s honestly the absolute BEST way to handle this situation. I didn’t explain it before because it might be a bit too complicated, but hear me out:
In summary, you’re going to do everything here on the client, but you’re also going to listen to OTHER players’ humanoids on your client as well:
Player takes damage
On that player’s client, we do the damage indicator script
Another player loads into the game
Upon them joining we listen to their humanoid as well, and run the damage indicator script on them when they take damage
Here’s a reference to get you started on listening for when other players’ characters get added btw, you might even be able to just paste your code under the CharacterAdded() function directly and it may work:
The reason why this is the best is because everything is done on your client. You have the added protection of only reacting to what the server authorizes, so no exploit potential. It also is “cleaner” code in a way, since it’s only reactive to what’s happening on your client.