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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 05 Nov 2009 |
| Total Posts: 285 |
|
|
| 14 Feb 2015 04:00 AM |
| Woah that works! thanks for helping out people! |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 25 May 2009 |
| Total Posts: 13385 |
|
| |
|