hi,
how would I make it so the server always checks whether the current_health value is below a certain percentage? Whenever I regenerate my health, the health bar does not update therefore it's still yellow instead of green! Plus sometimes <= or >= don't work.
local health = game.Players.LocalPlayer.Character:WaitForChild("Humanoid") local bar = script.Parent.Parent local current_health = health.Health / 100 local runService = game:GetService("RunService") health.HealthChanged:connect(function() runService.Stepped:connect(function() bar.Size = UDim2.new((health.Health / 100) * 1,0,1,0) if current_health >=.51 then --green bar.BackgroundColor3 = Color3.fromRGB(79, 222, 1) bar.BorderColor3 = Color3.fromRGB(61, 172, 2) print'green' elseif current_health <=.5 then -- yellow bar.BackgroundColor3 = Color3.fromRGB(222, 171, 42) bar.BorderColor3 = Color3.fromRGB(173, 133, 32) print'yellow' elseif current_health <=.3 then --red bar.BackgroundColor3 = Color3.fromRGB(222, 75, 55) bar.BorderColor3 = Color3.fromRGB(166, 55, 41) print'red' -- end end) end)
thanks, hydrogyn
local health = game.Players.LocalPlayer.Character:WaitForChild("Humanoid") local bar = script.Parent.Parent local runService = game:GetService("RunService") health.HealthChanged:connect(function(new_health) local current_health = new_health / 100 bar.Size = UDim2.new((new_health / 100) * 1,0,1,0) if current_health >=.51 then --green bar.BackgroundColor3 = Color3.fromRGB(79, 222, 1) bar.BorderColor3 = Color3.fromRGB(61, 172, 2) print('green') elseif current_health <=.5 and current_health >=.3 then -- yellow bar.BackgroundColor3 = Color3.fromRGB(222, 171, 42) bar.BorderColor3 = Color3.fromRGB(173, 133, 32) print('yellow') elseif current_health <=.3 then --red bar.BackgroundColor3 = Color3.fromRGB(222, 75, 55) bar.BorderColor3 = Color3.fromRGB(166, 55, 41) print('red'9) end end)