I have been having trouble with making a custom health bar. What will happen is that it works when you are losing health and die, but it will immediately stop working after you respawn into the game.
local player = game.Players.LocalPlayer local char = player.Character local hum = char:WaitForChild("Humanoid") local TweenService = game:GetService("TweenService") hum.Changed:connect(function(health) if health == "Health" or health == "MaxHealth" then local bar = script.Parent local info = TweenInfo.new(0.15, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut) local goal = {["Size"] = UDim2.new((hum.Health/hum.MaxHealth), 0, 1, 0)} TweenService:Create(bar, info, goal):Play() script.Parent.Parent.TextLabel.Text = ("Health: " .. math.floor(hum.Health).."/".. math.floor(hum.MaxHealth)) end end)
Any help is appreciated.
add this at the top and it should work
local char = player.Character if not char or not char.Parent then char = player.CharacterAdded:wait() end