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

What is wrong with this color-changing health GUI script?

Asked by 9 years ago

This is supposed to change the color of the HP Gui depending on a player's HP. The problem is that the color always stays as yellow. And I was supposed to add a wait() somewhere, but I forgot. This script is a regular script parented to the GUI.

while true do
if script.Parent.Parent.Parent.Character.Humanoid.Health > 50 then
script.Parent.Frame.BackgroundColor3 = Color3.new(85,225,0) -- I think that was for green. If not, please fix it.
elseif script.Parent.Parent.Parent.Character.Humanoid.Health < 50 and script.Parent.Parent.Parent.Character.Humanoid.Health > 20 then -- I just added the "and" to this, not in the original script, so I am not sure if it will fix my script or not.
script.Parent.Frame.BackgroundColor3 = Color3.new() -- I forgot what yellow was c:
elseif script.Parent.Parent.Parent.Character.Humanoid.Health < 20 then
script.Parent.Frame.BackgroundColor3 = Color3.new(255,0,0) -- I think this was red. If not, please fix it.
end
1
Do you receive any error messages from running this script? Also besides adding wait() (which is a must for a "while true do" loop), I would highly recommend looking into using the event "HealthChanged" in the Humanoid instead of the while loop. See here: http://wiki.roblox.com/index.php?title=API:Class/Humanoid/HealthChanged. SanityMan 239 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

First thing is your game will crash if you don't put a wait in your while loop like this

while true do
    wait()
    --code
end

or

while wait() do
    --code
end

The reason it's yellow is because Color3.new() goes from 0 to 1. 0 representing 0 out of 225, and 1 representing 225 out of 225. If you want it green do this:

script.Parent.Frame.BackgroundColor3 = Color3.new(0,1,0)

For Color3.new() if you wanted yellow, do this:

script.Parent.Frame.BackgroundColor3 = Color3.new(1,1,0)

And for red all you'd have to do is:

script.Parent.Frame.BackgroundColor3 = Color3.new(1,0,0)
0
Thanks! groovydino 2 — 9y
Ad

Answer this question