It's supposed to make my custom health bar change the color from red to green, and change the size, but it doesn't do anything, why?
function barFunction(plr) -- supposed to make me custom health bar work
local gui = plr.PlayerGui:WaitForChild("Health", 99)
local hbar = gui:WaitForChild("Bar", 99)
local playerhp = gui:WaitForChild("PlayerHealth", 99)
local maxhealth = gui:WaitForChild("MaxHealth", 99)
local percent = playerhp.Value / maxhealth.Value
playerhp.Changed:connect(function()
--//color
local green = percent
local red = 1 - green
hbar.BackgroundColor3 = Color3.new(red,green,0)
--//size
hbar.Size = UDim2.new(0,percent * x,0,y)
end)
end
game.Players.PlayerAdded:Connect(function(plr)
barFunction(plr) -- launches it
end)

2 comments
you cant use the playeradded event inside a local script
Edit: Marked as solved