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: Help with the this gui script!!

Previous Thread :: Next Thread 
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
14 Feb 2015 03:14 AM
hi, im making a custom healthbar gui for my rpg game, but i cant get it to work.

while true do
script.Parent.Text = "Health: " .. math.floor(script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.Health) .. "/" .. math.floor(script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.MaxHealth)
wait(0.1)
end



output says on line 2; stack end. (line 2 starts from script.Parent.Text)
Report Abuse
drager980 is online. drager980
Joined: 25 May 2009
Total Posts: 13385
14 Feb 2015 03:43 AM
while wait(0.1) do
script.Parent.Text = "Health: " .. math.floor(script.Parent.Parent.Parent.Parent.Parent:WaitForChild("Character"):WaitForChild("Humanoid").Health) .. "/" .. math.floor(script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid.MaxHealth)
end

you didnt paste the entire output so idk lol
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
14 Feb 2015 03:47 AM
Why does no one use the HealthChanged event for health guis
Report Abuse
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
14 Feb 2015 03:48 AM
i tried your script, it doesnt work nor show any output lol
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
14 Feb 2015 03:49 AM
Drager Character is not a child of Player so waitForChild("Character") won't work
Report Abuse
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
14 Feb 2015 03:54 AM
i tried HealthChanged() and it works perfectly fine but the only problem is that it shows decimal numbers like 47.023123421 i want it to show integers such as 50, 20, 40, 0
Report Abuse
Rocky28447 is online. Rocky28447
Joined: 11 Dec 2009
Total Posts: 2912
14 Feb 2015 03:56 AM
Either:

A) Put a rounding function

or

B) Insert an IntValue and set the IntValue's value to the health and set the text to the IntValue's value.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
14 Feb 2015 03:58 AM
local humanoid = (game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:wait()):WaitForChild("Humanoid")

humanoid.HealthChanged:connect(function()
script.Parent.Text = ("Health: " .. math.floor(humanoid.Health + 0.5) .. "/" .. math.floor(humanoid.MaxHealth + 0.5))
end)
Report Abuse
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
14 Feb 2015 03:58 AM
Thanks for actually putting out sensible choices xD ill try both now.
Report Abuse
RoboX790 is not online. RoboX790
Joined: 05 Nov 2009
Total Posts: 285
14 Feb 2015 04:00 AM
Woah that works! thanks for helping out people!
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
14 Feb 2015 04:03 AM
If it doesn't work outside of studio, make sure the script is in a 'LocalScript' and not just a 'Script'
Report Abuse
drager980 is online. drager980
Joined: 25 May 2009
Total Posts: 13385
14 Feb 2015 04:35 AM
ty for the mental note 128gb,
but whats with doing game.Players.LocalPlayer.Character before
or game.Players.LocalPlayer.CharacterAdded:wait()):WaitForChild("Humanoid")?




AND THE TIGER GOES ROAR
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
14 Feb 2015 04:42 AM
local x = (nil or 5)
print(x) -->5

x = (6 or 5)
print(x) -->6


x = (false or 4)
print(x) -->4



If the first one is false or nil, it will be the second one

So

local character = (localPlayer.Character or localPlayer.CharacterAdded:wait())

if localPlayer.Character is nil, it will wait for CharacterAdded to fire and return the character

If localPlayer.Character is not nil, it will skip the wait part



So its like


local character = (character or wait for character):WaitForChild("Humanoid")
Report Abuse
drager980 is online. drager980
Joined: 25 May 2009
Total Posts: 13385
14 Feb 2015 04:56 AM
ty



AND THE TIGER GOES ROAR
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