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: HP gui blues

Previous Thread :: Next Thread 
ArmaVictorem is online. ArmaVictorem
Joined: 18 Mar 2015
Total Posts: 1332
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
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
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
ArmaVictorem is online. ArmaVictorem
Joined: 18 Mar 2015
Total Posts: 1332
04 Jul 2016 08:52 PM
that many elementary mistakes?

it works now

lol thanks!
Report Abuse
ArmaVictorem is online. ArmaVictorem
Joined: 18 Mar 2015
Total Posts: 1332
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
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
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
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