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

I need help with a image label in startgui to turn off and on based on health?

Asked by 2 years ago
Edited 2 years ago

hi im new here and i've been having problems with this certain code that i made (im new at this sorry if it looks bad) the point of the code is to make it so if your health is at for example 3 on starter gui it would display a custom imagelabel. and would apreciate it if someone could help me out with it? for example when the health is at 3 it would display a custom imagelabel that i made that has a 3 on it (the max health is 3)

local guiObject = script.Parent
local gui = script.Parent
local plr = game.Players.LocalPlayer;
local character = plr.Character or plr.CharacterAdded:Wait();
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local currentHealth = humanoid.Health
local hum = character:WaitForChild("Humanoid");

local function health()
    if hum.Health == 3 then
        guiObject.Visible = true
    else
        guiObject.Visible = false
end
    humanoid.HealthChanged:Connect(function(health)
    end)

sorry if it seems messy im new to this all and after trying to search around for a while i just realized that i got no idea .

0
So in your health 3,2,1 system, is it based on how much health the player has? like in the default health bar? Xyternal 247 — 2y
0
Also is this a server, or a local script? Xyternal 247 — 2y
0
yeah it is based off of how much health the players has also it is a local script that i put in under the imagelabel in starter gui davidjiang 0 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if humanoid.Health == 3 then
 guiObject.Visible = true
else
 guiObject.Visible = false
end
end)

0
Also check you are using 2 variables to assign script.Parent, i assume you don't want to assign script.Parent twice so you can use script.Parent.Parent depending on how you organized it Shadic1270 136 — 2y
Ad

Answer this question