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

What is wrong with this health bar script?

Asked by
Mystdar 352 Moderation Voter
9 years ago

The purpose is to have a health bar, a bit like Skyrim's where it gets closer to the middle, depending on health, but the second part will change its colour, i'm sure I went wrong in several places, none of it works, I could of gone wrong with (I have given the GUI a size and colour to begin with, in its actual properties). I'm fairly sure GUIs do not have brickcolors, but I don't know how to put the Red, Blue, Green properties in it.

It is meant to be unique for each player too. The script is in the Starter GUI, inside a Screen GUI, inside a Frame.

local Frame= script.Parent
local health = script.Parent.Parent.Parent.Parent.Character.humanoid.Health.Value


while true do
    wait(0.1)
    Frame.Size=Frame.Size.new{0, health},{0, 5}
end

while true do
    wait(0.05)
    if health==100>=75 then
    Frame.BackgroundColor3= Frame.BackgroundColor3.new ("Dark Green")
    end -- If your health is from 100 to 75 then make the bar, this color
    elseif 
    health==74>=50 then
    Frame.BackgroundColor3= Frame.BackgroundColor3.new ("Grime")
    end 
    elseif 
    health==49>=25 then
    Frame.BackgroundColor3= Frame.BackgroundColor3.new ("Cool Yellow")
    end 
    elseif 
    health==24>=0 then
    Frame.BackgroundColor3= Frame.BackgroundColor3.new ("Bright Red")
    end 
end


0
Just a warning, putting this script into StarterGui will make it to where all players see one change. It won't be specific per person. you instead need to clone it into each player's PlayerGui by whatever mean you see best. (I would suggest with a PlayerAdded event) RoboFrog 400 — 9y
0
Thanks for the advice! Mystdar 352 — 9y
0
The humanoid is with capital H, also. Tesouro 407 — 9y
0
About the color, Color3 is the rgb color system, but instead of being numbered 0 to 255, it's 0 to 1. Black would be (0, 0, 0) and white (1, 1, 1), for example. Tesouro 407 — 9y

Answer this question