Ignore the title...
So uhh... Yeah... Im trying to make it when the character has taken damage... a gui shows up... Okay here's what i put
local hum = script.Parent.Humanoid local RG = game.Players.LocalPlayer.PlayerGui.DamageGui hum.HealthChanged:Connect(function() RG.Enabled = true wait(2) RG.Enabled = false end)
This is in Starter Character... Instead of when Damaged... It does it when it is healing and stuff to... How could i make this where the GUI only pops up on Damage.
The solution is to check if the health is going down, here is how.
local PreviousHealth = 101 local hum = script.Parent.Humanoid local RG = game.Players.LocalPlayer.PlayerGui.DamageGui hum.HealthChanged:Connect(function() -- when changed.. if hum.Health < PreviousHealth then -- is the health less than the previous health? RG.Enabled = true -- open ui wait(2) RG.Enabled = false -- close ui end PreviousHealth = hum.Health -- set the health in case it goes up end)
If this helps, please click accept, if not message me in the comments. Good luck!
You can do this by keeping a variable which holds the previous health, then compare each time when it gets called and check if the current health is lower than the previous health
Example
local hum = script.Parent.Humanoid local RG = game.Players.LocalPlayer.PlayerGui.DamageGui local prevHealth = hum.Health hum.HealthChanged:Connect(function(health) if prevHealth > health then -- check if prev health is lower than current health RG.Enabled = true wait(2) RG.Enabled = false end prevHealth = health -- set the next previous health end)