What I'm trying to do is when the player's health reaches a certain point, a gui's background color changes to a certain color.
75+ = Green
50-75 = Orange
25-50 = Red
25- = Really Red
--To round the player's health on a gui
local function Round(x)
return math.floor(x+0.5)
end
local percent = script.Parent.Indicator.Percent
local indicator = script.Parent.Indicator
local player = game.Players.LocalPlayer
workspace:WaitForChild(player.Name)
local char = game.Workspace[player.Name].Humanoid
--green = 60, 255, 0
--red = 255, 38, 0
--reallyred = 255, 0, 0
--orange = 255, 160, 0
char.Changed:connect(function()
indicator.Size = UDim2.new(char.Health/100, 0, 1, 0)
percent.Text = Round(char.Health).."%"
if char.Health >= 75 then --Green
indicator.BackgroundColor3 = Color3.new(60, 255, 0)
elseif char.Health >= 50 and char.Health <= 75 then --Orange
indicator.BackgroundColor3 = Color3.new(255,160, 0)
elseif char.Health <= 50 and char.Health >= 25 then --Red
indicator.BackgroundColor3 = Color3.new(255, 38, 0)
elseif char.Health <= 25 then --Really Red
indicator.BackgroundColor3 = Color3.new(255, 0, 0)
end
end)
--For testing purposes
local healthh = math.random(1,99)
wait(10)
char.Health = char.Health - healthh
