Hello! I’m trying to make a life system that gives you 3 lives.
I need help on how to detect if a life deducted or added and how to apply the changes into a ui image .
Example: if a life is dectucted (life.Value = life.Value - 1) then a heart in ui frame get destroyed
but if a life get added another heart get added to the ui frame.
Just set the transparency of the third heart to 1 when a life is lost. Check the options for transparency of the heart in the properties tab and change the values as you see fit. You could introduce a loop that makes the heart slowly fade out. ImageLabel | Documentation - Roblox Creator Hub
repeat wait() until game.Players.LocalPlayer.Character
plr = game.Players.LocalPlayer
c = plr.Character
humanoid = c:WaitForChild("Humanoid")
LifeThing = script.Parent.Backround
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if humanoid.Health <= 75 then
LifeThing.Life4.Visible = false
elseif Humanoid.Health <= 50 then
LifeThing.Life3.Visible = false
elseif Humanoid.Health <= 25 then
LifeThing.Life2.Visible = false
elseif Humanoid.Health <= 0 then
LifeThing.Life1.Visible = false
end
end)
This should work and make sure there is a fourth gui and call it life4
if intvalue.value == 1 then
-- hide all the hearts except for the last one
heart1.Imagetransparency = 0
heart2.Imagetransparency = 1
heart3.Imagetransparency = 1
elseif intvalue.value == 2 then
-- only hide the third heart
heart1.Imagetransparency = 0
heart2.Imagetransparency = 0
heart3.Imagetransparency = 1
elseif intvalue.value == 3 then
-- Unhide all hearts
heart1.Imagetransparency = 0
heart2.Imagetransparency = 0
heart3.Imagetransparency = 0
end
Note: this is not the most efficient way to do this, but it is the easiest to understand
Try putting something like this in a local script under “Background”
local Background = script.Parent
local lifevalue = -- make an int value, define it, and change that int value whenever u want to change the Gui.
local lastlife = lifevalue.Value --We will use later to detect if the lives increased or decreased
lifevalue.Changed:Connect(function()
if lifevalue > lastlife then --we know that they gained a life
Background:FindFirstChild("Life"..lifevalue.Value).ImageTransperancy = 0 --say they now have 2 lives we will take "Life2" and make it visible
else -- we know that they lost a life
Background:FindFirstChild("Life"..lifevalue.Value+1).ImageTransperancy = 1
end
lastlife = lifevalue.Value
end)