Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Health bar local script not working?

Asked by 5 years ago
Edited 5 years ago

In my local script for a health bar I have, it seems to not be moving at all with the current code I have.

Here is the script:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait() or workspace:WaitForChild(player.Name)
local humanoid = character:WaitForChild("Humanoid")

humanoid.HealthChanged:Connect(function(health)
    script.Parent.Bar.Size = UDim2.new(health / humanoid.MaxHealth, 0, 1, 0)

    if humanoid.Health / humanoid.MaxHealth > script.Parent.Damage.Size.X.Scale then
        script.Parent.Damage.Size = UDim2.new(health / humanoid.MaxHealth, 0, 1, 0)
    else
        script.Parent.Damage:TweenSize(UDim2.new(health / humanoid.MaxHealth, 0, 1, 0), nil, Enum.EasingStyle.Linear, 0.5, true)
    end
end)

player:WaitForChild("CombatTags").ChildAdded:Connect(function()
    local cnum = #player.CombatTags:GetChildren()

    if cnum == 0 then
        script.Parent.Hint.Visible = false
    else
        script.Parent.Hint.Visible = true
    end
end)

player:WaitForChild("CombatTags").ChildRemoved:Connect(function()
    local cnum = #player.CombatTags:GetChildren()

    if cnum == 0 then
        script.Parent.Hint.Visible = false
    else
        script.Parent.Hint.Visible = true
    end
end)

I have talked with serveral friends on this secetion of code and they as well see nothing wrong with it.

0
What is the “script.Parent.Health.Damage.Size.X.Scale” on line 8 actually referring to? ABK2017 406 — 5y
0
Fixed. Still doesn't work however. FireyMcBlox 134 — 5y
0
I didn't see an error for line 8, so I had no idea. Thank you for pointing it out. FireyMcBlox 134 — 5y

Answer this question