local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = character:FindFirstChild("Humanoid")
local image = script.Parent
humanoid.Health.Changed:Connect(function(newvalue)
if newvalue <= 100 then
image.Image = "https://www.roblox.com/library/7917732450/100hpicon"
elseif newvalue <= 75 then
image.Image = "https://www.roblox.com/library/7917733668/75hp"
elseif newvalue <= 50 then
image.Image = "https://www.roblox.com/library/7917734933/50hp"
elseif newvalue <= 35 then
image.Image = "https://www.roblox.com/library/7917736453/35hpicon"
elseif newvalue <= 20 then
image.Image = "https://www.roblox.com/library/7917737527/20hpicon"
end
end)
Doesn’t seem to work, this is the error i got: 19:15:10.696 Players.Ballora544.PlayerGui.HealthGUI.Frame.Frame.ImageLabel.LocalScript:6: attempt to index number with ‘Changed’ - Client - LocalScript:6
Turns out, this was the solution! We just had to place a > at the and newvalue, I’m gonna mark this solution since it’s basically only missing one symbol. Thank you so much, you helped me a lot on this.
Full script:
local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local image = script.Parent
humanoid.HealthChanged:Connect(function(newvalue)
if newvalue <= 100 and newvalue >= 75 then
image.Image = "http://www.roblox.com/asset/?id=7917732393"
end
if newvalue <= 75 and newvalue >= 50 then
image.Image = "http://www.roblox.com/asset/?id=7917733637"
end
if newvalue <= 50 and newvalue >= 35 then
image.Image = "http://www.roblox.com/asset/?id=7917734910"
end
if newvalue <= 35 and newvalue >= 20 then
image.Image = "http://www.roblox.com/asset/?id=7917736411"
end
if newvalue <= 20 then
image.Image = "http://www.roblox.com/asset/?id=7917737512"
end
end)
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer or plrs.PlayerAdded:Wait()
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = character:WaitFirstChild("Humanoid")
local image = script.Parent
local healths = {100, 75, 50, 35, 20}
local assetIds = {7917732393, 7917733637, 7917734910, 7917736411, 7917737512}
humanoid.HealthChanged:Connect(function(newvalue)
for i = 1, #healths do
if newvalue <= healths[i] and newvalue > (healths[i+i] or 0) then
image.Image = "http://www.roblox.com/asset/?id="..assetIds[i]
end
end
end)