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 » Scripters
Home Search
 

Re: Simple Health Bar wont work?

Previous Thread :: Next Thread 
zachattack220 is not online. zachattack220
Joined: 20 Jan 2013
Total Posts: 2196
14 Dec 2015 01:12 AM
local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid
local health = humanoid.Health
local maxhealth = humanoid.MaxHealth

while true do
wait(0.30)
game.StarterGui.hp.TextLabel.Text=(health .. "/" .. maxhealth)
end



-zachattack220
Report Abuse
NormaINorm is not online. NormaINorm
Joined: 11 Dec 2012
Total Posts: 315
14 Dec 2015 01:28 AM
after the player variable put:

repeat wait() until player.Character
Report Abuse
zachattack220 is not online. zachattack220
Joined: 20 Jan 2013
Total Posts: 2196
14 Dec 2015 01:50 AM
@NormalNorm

Still dosnt seem to work.



-zachattack220
Report Abuse
NormaINorm is not online. NormaINorm
Joined: 11 Dec 2012
Total Posts: 315
14 Dec 2015 02:01 AM
By the way; I wouldn't use a while loop to display the humanoid's health/maxhealth. Used a .Changed event on the humanoid instead. It's much more efficient.
Report Abuse
010011011 is not online. 010011011
Joined: 12 Dec 2015
Total Posts: 400
14 Dec 2015 02:02 AM
Number and String concentanted? Not sure about that try to tostring(health) and tostring(maxhealth) and see how that goes!


Cheers
Report Abuse
T00NAMI is not online. T00NAMI
Joined: 10 Mar 2013
Total Posts: 211
14 Dec 2015 06:21 AM
The problem is you are making changes to: game.StarterGui
When players join a game, all the gui's within game.StarterGui get cloned into player.PlayerGui

So make the changes into player.PlayerGui instead.
And if you have FilteringEnabled on, you need to use remote functions. But I don't think you do so don't worry about this technical detail.

Try something like this:

local Player = game.Players.LocalPlayer
repeat wait() until Player and Player.Character
local Humanoid = Player.Character:WaitForChild("Humanoid")
local HealthGui = Player.PlayerGui:WaitForChild("hp")
local HealthLabel = HealthGui:WaitForChild("TextLabel")

Humanoid.Changed:connect(function(property)
if property == Health then
HealthLabel.Text = Humanoid.Health.." / "..Humanoid.MaxHealth
end
end)


If it doesn't work, then one of the WaitForChild()'s probably couldn't find it.
TIP: use prints in various places to debug your scripts.
Report Abuse
CLIMAXIMUS is not online. CLIMAXIMUS
Joined: 22 Jun 2012
Total Posts: 1738
14 Dec 2015 06:28 AM
-- This is more efficient, and makes more sense.

local Player = game:GetService("Players").LocalPlayer
local Humanoid = Player.CharacterAdded:wait():WaitForChild("Humanoid")
local HealthLabel = Player.PlayerGui:WaitForChild("hp"):WaitForChild("TextLabel")

Humanoid.HealthChanged:connect(function(Health)
HealthLabel.Text = Health.." / "..Humanoid.MaxHealth
end)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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