I'm trying to make a health bar while not using the player's actual health. I'm trying to use an Integer Value to replace the player's health. This is my code but it seems that the Instance.new isn't working.
wait(1) --Variables local player = game.Players.LocalPlayer local character = player.Character local humanoid = character.Humanoid local hpBar = script.Parent.Bar --Functions game.Players.PlayerAdded:Connect(function() local health = Instance.new("IntValue") health.Name = "Health" health.Parent = player health.Value = 100 end) function Update() local hp = player.Health.Value / 100 - 0.02 if hp > 2 then hpBar:TweenSize(UDim2.new(hp, 0, 0.85, 0)) else humanoid.Health = 0 end end Update() player.Health.Changed:Connect(Update)
I have some possible conclusions:
Is this a local script? If it is you should put it in playerStarterScripts or something like that.
You shouldn't set the Instance.New() to local, it needs to be global
Check if the script even runs with debug print("test")