|
| 04 Jul 2016 08:35 PM |
it's my first time working with guis and I have no idea what I did wrong, can anyone help? thanks in advance!
local player = game.Players:WaitForChild("LocalPlayer") local humanoid = player:WaitForChild("Humanoid") local hp = script.Parent
hp.size = UDim2.new((humanoid.Health / humanoid.MaxHealth)* 0,400,0,50)
if humanoid.Health <= 100 then hp.BackgroundColor3 = Color3.new(225,255,0) end
if humanoid.Health <= 50 then hp.BackgroundColor3 = Color3.new(225,255,0) end
if humanoid.Health <= 25 then hp.BackgroundColor3 = Color3.new(225,255,0) end
|
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 08:44 PM |
1) LocalPlayer is a property, not a child. Therefore, WaitForChild isn't needed and will actually break your script.
2) The player object isn't the character, so you won't find the humanoid that way. Thankfully, the player object has a property named Character that points to it. It's the same as LocalPlayer: you will not be able to use WaitForChild. Instead, we will tell the script to wait for the CharacterAdded event if the Character property is nil.
local character = player.Character or player.CharacterAdded:wait() local humanoid = player:WaitForChild("Humanoid")
3) size needs to be Size. Your math might not be right on that line either, as you are multiplying by 0.
4) Color3.new() takes 3 decimals (0-1). If you want to keep your numbers the same, Color3.fromRGB() takes 3 integers (0-255).
5) You should connect the bulk of your code to the HealthChanged event of Humanoid so that it recalculates the healthbar whenever there is a change.
"Tell me and I forget. Teach me and I remember. Involve me and I learn." - Benjamin Franklin |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 08:52 PM |
that many elementary mistakes?
it works now
lol thanks! |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 08:54 PM |
| I also forgot to put the wait loop but the HealthChanged event should be more efficient since it dosen't check every second I guess |
|
|
| Report Abuse |
|
|
|
| 04 Jul 2016 08:58 PM |
It's alright.
The waiting stuff is important for defining character, but not for the player. It's safe to assume LocalPlayer exists, because if it didnt, your script wouldnt exist either.
"Tell me and I forget. Teach me and I remember. Involve me and I learn." - Benjamin Franklin |
|
|
| Report Abuse |
|
|