Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Need help Completing My System? NEW

Asked by 3 years ago

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.

2 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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!

Ad
Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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)
0
n000000000 im too SLOW greatneil80 2647 — 3y
0
how did you get upvoted and i dont ?? VerdommeMan 1479 — 3y
0
bro idk greatneil80 2647 — 3y
0
There... THX ALL OF YOU GUYS!!!!!! malachiRashee 24 — 3y
View all comments (3 more)
0
Alright now imma go to sleep... malachiRashee 24 — 3y
0
Ima upvote this because you did exactly what I did. greatneil80 2647 — 3y
0
Great minds think alike ;) greatneil80 2647 — 3y

Answer this question