local PS = game:GetService("Players")
local player = PS.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum: Humanoid = char:WaitForChild("Humanoid")
local oldHealth = hum.Health
hum.HealthChanged:Connect(function()
local change = oldHealth - hum.Health -- this is the amount of damage taken
oldHealth = hum.Health
if change > oldHealth or change < 0 then
return
end
warn(change)
end)
From this, you can probably incorporate this into your own code.
I think we can do something like fire back to client of the player who attack with the damage and form that we add it to the gui, bc the damage number show in server it might seem messy
The gist of the tutorial (and damage indicators in general):
When a client does damage to a target, the server fires a remote event to that client with the target, damage dealt, and type of indicator to spawn
The client receives the remote and creates the damage indicator with the damage dealt and correct style, places it on the target, then animates it with some tweening.
If you want to add the damage number batching that Arsenal has, in which multiple damage instances in a short timeframe are grouped into a single indicator:
Create a dictionary that will store a target and its corresponding damage indicator object as a key-value pair
When the client receives the event to create a damage indicator on a target, check if the target is in the dictionary
If no, create a new indicator object and place the target and object in the dictionary. Also add a countdown (using coroutines or task.delay) after which you remove the indicator from the list.
If yes, instead of creating a new indicator, instead add the damage dealt to the current indicator’s displaying number and display the sum.
Reset any active fading, position, or size tweens and replay them. Also reset the countdown for removing the indicator (cancel the thread and start a new one).
It sounds like what you are looking for is an information display system. What @Downrest illustrated is a damage direction indicator which tells you what direction the damage came from.
@devloperblox You can’t display it in the server. It has to display on the client which means firing a remote event to the client with the damage number, and the position in the 3d world. From there you have to get the 2d screen coordinate and display it in a TextLabel at those coordinates.
@Content_Corrupted019 has the correct answer with the tutorial on how to make such a system.