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

The numbers getting crazy How do I fix it?

Asked by 5 years ago

I made a custom hp bar, And the color supposed to be between red and green but the color keeps going to numbers like 69000 what is going on???

x = 314
y = 40


game.Players.PlayerAdded:Connect(function(plr)
    --//values\\
    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 persec = gui:WaitForChild("PerSecond", 99)
    local percent = playerhp.Value / maxhealth.Value
    --//connect\\
    playerhp.Changed:connect(function()
    playerhp = gui:WaitForChild("PlayerHealth", 99)
    maxhealth = gui:WaitForChild("MaxHealth", 99)
    persec = gui:WaitForChild("PerSecond", 99)
    percent = playerhp.Value / maxhealth.Value
        --//color\\
    local green = 255 * playerhp
    local red = 255 - green
    hbar.BackgroundColor3 = Color3.new(red,green,0)
        --//size\\
        hbar.Size = UDim2.new(0,(playerhp.Value / maxhealth.Value) * x,0,y)
    end)
    --//end connect\\
end)

please help!

0
playerhp is an objectvalue? and your equation is wrong, it should be: local green = 1 * percent INOOBE_YT 387 — 5y

1 answer

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago

Because Color3.new accepts numbers from 0 - 1 and you're passing higher numbers.

local green = percent
local red = 1 - percent

hbar.BackgroundColor3 = Color3.new(red, green, 0)
Ad

Answer this question