When I change the health of the part it doesn't move to what it is supposed to be although it's in a while true do
local hum = script.Parent.Parent.Parent.Parent.Humanoid -- Put Humanoid name into MobGUI while true do script.Parent.HealthNum.Text = hum.Health .. "/" .. hum.MaxHealth -- This is Health Humanoid use "/" Health 100/100 or another number script.Parent.Healthbar.Size = UDim2.new(hum.Health/50,0,1,0) wait() end
Firstly, use LocalScript. Secondy, use LocalPlayer with Players service. Use product crossed to find the pourcent. Use the event "Changed".
(Humanoid.Health * 100 / Humanoid.MaxHealth) * 0.01
--< Services local PlayerService = game:GetService('Players') --< Variables local Player = PlayerService.LocalPlayer repeat wait() until Player.Character local Character = Player.Character local Humanoid = Character.Humanoid --< Events Humanoid.Changed:Connect(function() script.Parent.HealthNum.Text = Humanoid.Health .. "/" .. Humanoid.MaxHealth -- This is Health Humanoid use "/" Health 100/100 or another number script.Parent.Healthbar.Size = UDim2.new((Humanoid.Health * 100 / Humanoid.MaxHealth) * 0.01, 0, 1, 0) wait() end)
You can use TweenSize for a smooth resize effect.
script.Parent.Healthbar:TweenSize(UDim2.new((Humanoid.Health * 100 / Humanoid.MaxHealth) * 0.01, 0, 1, 0))