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

How to fire a function only if a value is lower than before?

health:GetPropertyChangedSignal("Value"):Connect(function()
        local currenttxt = "You have been hit! Use a bandage to restore health!"
        local newHint = game.ReplicatedStorage.GUIs.HintLine:Clone()
        newHint.Parent = player.PlayerGui.Main.Hint
        for i = 1,#currenttxt do
            newHint.Text = string.sub(currenttxt,1,i)
            wait(0.05)
        end

end)

How can I make this happen only if the player's health drops, and not increases?

1 answer

local formerhealth = {}

table.insert(formerhealth,1,health)
health:GetPropertyChangedSignal("Value"):Connect(function()
	if health < formerhealth[1] then
		table.remove(formerhealth,1)
		table.insert(formerhealth,1,health)
		-- do whatever you need to do now
	end
end)

1 comment

0

I have a bandage system in my game that increases the player's health, and this script only works if their health never increases.

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