After locating each player's health in humanoid, the HealthBar.Size.X.Offset should be the Health value every 0.5 seconds
The problem is here that the HealthBar.Size.X.Offset is not the value of the health. In this script, the X scale offset of HealthBar should be equal to the players health at all times. Especially because of the fact that I used while true do wait(0.5) HealthBar.Size = UDim2.new(0, Health, 0, 20) end
while true do
wait(0.5)
HealthBar.Size = Udim2.new(nil, Health, nil, 20)
end
-- However, I constantly kept testing this, and it doesn't work.
-- Character, Player, and Health.
Player = game.Players.LocalPlayer
PlayersName = Player.Name
print(PlayersName)
PlayersCharacter = Player.Character
PlayersHumanoid = PlayersCharacter.Humanoid
Health = PlayersHumanoid.Health
MaxHealth = PlayersHumanoid.MaxHealth
-- HealthBar and Measurements
MaxHealth = 300
Health = 300
HealthBar = script.Parent
-- Measurements
while true do
wait(0.5)
HealthBar.Size = UDim2.new(nil, Health, nil, 20)
--break
end
function Test()
if Health then
print("Players Health was found!")
end
print(PlayersName)
end
Test()
print(Health)

1 comment
You can't use nil in UDim2.new(). Also, please specify the error you are getting.