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

How to make this change red if your health is 25 or below?

It is part of my health gui. The health GUI is completley text based. I was wanting to know how I could make it turn red if your health is 25 or below.

local health = script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.Health
local mhealth = script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.MaxHealth
script.Parent.Text = string.sub(string.lower(health),1,3)..""
function onChange()
local health = script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.Health
local mhealth = script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.MaxHealth
script.Parent.Text = string.sub(string.lower(health),1,3)..""
end
script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.Changed:connect(onChange)




1 answer

Is this in a local script? If not.. I would suggest to do that.. It's a lot easier accessing the player...

local player = game.Players.LocalPlayer -- This defines the player
local health = player.Character.Humanoid.Health
local mhealth = player.Charecter.Humanoid.MaxHealth
function onChange()
	if player.Health < 26 then -- on 25 health or below...
		script.Parent.Color = Color3.new(1,0,0) -- Changes it to Red
	else
		script.Parent.Color = Color3.new(0,1,0) -- Changes it to Green
	end
end

player.Charecter.Humanoid.HealthChanged:connect(onChange)

This should work. if it doesn't respond and tell me what the error is.

1 comment

0

Do I make a new script inside the textbox?

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