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

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

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 .

3 comments

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?

0

Also is this a server, or a local script?

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

1 answer

humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if humanoid.Health == 3 then
 guiObject.Visible = true
else
 guiObject.Visible = false
end
end)

1 comment

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

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