Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

When something changes do something ?

Idk how to explain but example if a guy loses 10 hp, everytime he loses health his screen gets red how can u do that ?

EDIT: Okay heres the script i've done

local humanoid = game.Players.LocalPlayer.Character.Humanoid
local currentHealth = humanoid.Health
local Flash = script.Parent.Flash

humanoid.HealthChanged:connect(function(health)
	local change = math.abs(currentHealth - health)
	Flash.Visible = true
	wait(0.2)
	Flash.Visible = false
	currentHealth = health
end)

But when he regenerates health it shows up too! i only want to make it show ONLY when hes losing not getting health.

1 comment

1 answer

Use the Humanoid HealthChanged event. This even fires each time the humanoid's health has changed, with the new health as the argument. You can use this to detect how much damage a humanoid has taken.

local gui = script.Parent.Frame --The gui element
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local currentHealth = humanoid.Health --Store the previous health before the change.
humanoid.HealthChanged:connect(function(health) --Every time the health changes...
	local change = health - currentHealth --Get the change in health from the stored value.
	currentHealth = health --Store the new health so we can compare it later.
	if change <= -10 then --If the humanoid lost more than 10 health...
		gui.Visible = true
		wait(.2)
		gui.Visible = false
	end
end)

3 comments

0

Your script what it does is when u get HP the frame appears but i want it vice versa :P :/

0

Actually, wait your script doesn't even work ;-;

0

The script is just an example. You need to edit it to fit your needs.

This discussion is preserved as it was. New answers, comments, and votes are closed.