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)

2 comments
Is this a localscript or script?
because "LocalPlayer" from "Players" comes nil when server sided and "character" runs nil when client sided