generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Works once only?

Previous Thread :: Next Thread 
nightmare3o is not online. nightmare3o
Joined: 21 Jun 2008
Total Posts: 956
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
blobbyblob is not online. blobbyblob
Joined: 29 Oct 2008
Total Posts: 12165
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
nightmare3o is not online. nightmare3o
Joined: 21 Jun 2008
Total Posts: 956
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
nightmare3o is not online. nightmare3o
Joined: 21 Jun 2008
Total Posts: 956
17 Nov 2012 01:10 PM
bump
Report Abuse
blobbyblob is not online. blobbyblob
Joined: 29 Oct 2008
Total Posts: 12165
17 Nov 2012 01:11 PM
Don't replace the first line, just put that line before it.
Report Abuse
michaelaqz4 is not online. michaelaqz4
Joined: 23 Sep 2009
Total Posts: 1940
17 Nov 2012 01:11 PM
Put what Blob said right under

local humanoid = game.Players.LocalPlayer.Character
Report Abuse
nightmare3o is not online. nightmare3o
Joined: 21 Jun 2008
Total Posts: 956
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
michaelaqz4 is not online. michaelaqz4
Joined: 23 Sep 2009
Total Posts: 1940
17 Nov 2012 01:21 PM
Remove the "Local" at the top and then do what I said.
Report Abuse
1Topcop is not online. 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
nightmare3o is not online. nightmare3o
Joined: 21 Jun 2008
Total Posts: 956
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
michaelaqz4 is not online. michaelaqz4
Joined: 23 Sep 2009
Total Posts: 1940
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
nightmare3o is not online. nightmare3o
Joined: 21 Jun 2008
Total Posts: 956
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image