|
| 17 Nov 2012 12:29 PM |
local humanoid = game.Players.LocalPlayer.Character
if (humanoid.Humanoid == nil) then humanoid:Destroy() end
function UpdateGUI(health) local pgui = game.Players:GetPlayerFromCharacter(humanoid) local tray = pgui.PlayerGui.MainPlayGui.PlayerHealth.Bar.HealthDisplay tray:TweenSize(UDim2.new(0.8 * humanoid.Humanoid.Health , 0, 0.699999988, 0)) if humanoid.Humanoid.Health <= humanoid.Humanoid.MaxHealth / 3 then tray.Image = "http://www.roblox.com/asset/?id=97896357" --RED elseif humanoid.Humanoid.Health <= humanoid.Humanoid.MaxHealth / 2 then tray.Image = "http://www.roblox.com/asset/?id=97896345" --YELLOW elseif humanoid.Humanoid.Health > humanoid.Humanoid.MaxHealth / 1.4 then tray.Image = "http://www.roblox.com/asset/?id=97896326" --GREEN end end
function HealthChanged(health) UpdateGUI(health) end
humanoid.Humanoid.HealthChanged:connect(HealthChanged)
So the script is basically alexnewtron's health bar script that I editted The script works fine but once the players dies once the health bar doesn't seem to change size. The output says that humanoid is a nil value. |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 12:34 PM |
Add this to the first line, before anything else.
while game.Players.LocalPlayer.Character.Humanoid.Health==0 do wait(); end
The problem is that local scripts in the backpack or playergui often load before the character does. This causes the character value (in this case, the variable 'humanoid') to be set to the old character, not the new one. |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 12:41 PM |
After putting that in I got this now it's saying humanoid is a nil value on the last line attempt to index local 'humanoid' (a nil value) |
|
|
| Report Abuse |
|
|
| |
|
|
| 17 Nov 2012 01:11 PM |
| Don't replace the first line, just put that line before it. |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 01:11 PM |
Put what Blob said right under
local humanoid = game.Players.LocalPlayer.Character |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 01:20 PM |
Players.Player1.PlayerGui.MainPlayGui.PlayerHealth.Bar.Loca:1: attempt to index field 'Character' (a nil value)
This is just getting weird. |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 01:21 PM |
| Remove the "Local" at the top and then do what I said. |
|
|
| Report Abuse |
|
|
1Topcop
|
  |
| Joined: 09 Jun 2009 |
| Total Posts: 6635 |
|
|
| 17 Nov 2012 01:22 PM |
Replace this, local humanoid = game.Players.LocalPlayer.Character
if (humanoid.Humanoid == nil) then humanoid:Destroy() end
With this,
wait() local Player = game.Players.LocalPlayer local humanoid = nil repeat wait() humanoid = Player.Character:FindFirstChild("Humanoid") until Humanoid |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 01:23 PM |
This is what I have.
while game.Players.LocalPlayer.Character.Humanoid.Health==0 do wait(); end humanoid = game.Players.LocalPlayer.Character
if (humanoid.Humanoid == nil) then humanoid:Destroy() end
function UpdateGUI(health) local pgui = game.Players:GetPlayerFromCharacter(humanoid) local tray = pgui.PlayerGui.MainPlayGui.PlayerHealth.Bar.HealthDisplay tray:TweenSize(UDim2.new(0.8 * humanoid.Humanoid.Health , 0, 0.699999988, 0)) if humanoid.Humanoid.Health <= humanoid.Humanoid.MaxHealth / 3 then tray.Image = "http://www.roblox.com/asset/?id=97896357" --RED elseif humanoid.Humanoid.Health <= humanoid.Humanoid.MaxHealth / 2 then tray.Image = "http://www.roblox.com/asset/?id=97896345" --YELLOW elseif humanoid.Humanoid.Health > humanoid.Humanoid.MaxHealth / 1.4 then tray.Image = "http://www.roblox.com/asset/?id=97896326" --GREEN end end
function HealthChanged(health) UpdateGUI(health) end
humanoid.Humanoid.HealthChanged:connect(HealthChanged) |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 01:27 PM |
while game.Players.LocalPlayer.Character.Humanoid.Health==0 do wait() humanoid = game.Players.LocalPlayer.Character
if (humanoid.Humanoid == nil) then humanoid:Destroy() end
function UpdateGUI(health) local pgui = game.Players:GetPlayerFromCharacter(humanoid) local tray = pgui.PlayerGui.MainPlayGui.PlayerHealth.Bar.HealthDisplay tray:TweenSize(UDim2.new(0.8 * humanoid.Humanoid.Health , 0, 0.699999988, 0)) if humanoid.Humanoid.Health <= humanoid.Humanoid.MaxHealth / 3 then tray.Image = "http://www.roblox.com/asset/?id=97896357" --RED elseif humanoid.Humanoid.Health <= humanoid.Humanoid.MaxHealth / 2 then tray.Image = "http://www.roblox.com/asset/?id=97896345" --YELLOW elseif humanoid.Humanoid.Health > humanoid.Humanoid.MaxHealth / 1.4 then tray.Image = "http://www.roblox.com/asset/?id=97896326" --GREEN end end
function HealthChanged(health) UpdateGUI(health) end
humanoid.Humanoid.HealthChanged:connect(HealthChanged) |
|
|
| Report Abuse |
|
|
|
| 17 Nov 2012 01:50 PM |
Soo.... I ended up putting wait(5) on the first line and it works now... Thanks for the help guys. |
|
|
| Report Abuse |
|
|