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

My custom health bar script isn't working, Why? [solved]

Asked by 6 years ago
Edited by Shawnyg 6 years ago

It's supposed to make my custom health bar change the color from red to green, and change the size, but it doesn't do anything, why?

function barFunction(plr) -- supposed to make me custom health bar work
    local gui = plr.PlayerGui:WaitForChild("Health", 99)
    local hbar = gui:WaitForChild("Bar", 99)
    local playerhp = gui:WaitForChild("PlayerHealth", 99)
    local maxhealth = gui:WaitForChild("MaxHealth", 99)
    local percent = playerhp.Value / maxhealth.Value
    playerhp.Changed:connect(function()
        --//color
        local green = percent
        local red = 1 - green
        hbar.BackgroundColor3 = Color3.new(red,green,0)
        --//size
        hbar.Size = UDim2.new(0,percent * x,0,y)
    end)
end


game.Players.PlayerAdded:Connect(function(plr)
    barFunction(plr) -- launches it
end)
0
you cant use the playeradded event inside a local script User#23365 30 — 6y
0
Edit: Marked as solved Shawnyg 4330 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Nevermind, Solved I can do a loop.

0
theres a much better way of using a loop like using the HealthChanged event on the humanoid User#23365 30 — 6y
1
Didn't need to write an answer. Could've commented or edited the question Shawnyg 4330 — 6y
0
^ yup LisaF854 93 — 6y
Ad

Answer this question