Ahrinmor
|
  |
| Joined: 25 Dec 2012 |
| Total Posts: 534 |
|
|
| 31 Jan 2015 06:57 PM |
This is the code for a health bar I wrote. It runs fine in solo testing, but in test and live servers it just gives me an error in the output (below) and I'm not sure why. Everything is in the correct places and I've tried it a few different ways, but I'm still not sure what's causing it to fail. ____ Code
char = game.Players.LocalPlayer.Character hum = char.Humanoid hum.Changed:connect(function() script.Parent.Frame.Healthbar.Health.Size = UDim2.new(hum.Health/hum.MaxHealth-0.02,0,0.8,0) end)
____ Output
18:54:50.235 - Players.Player1.PlayerGui.ServerGui.LocalScript:2: attempt to index global 'char' (a nil value) |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2015 07:01 PM |
char = game.Players.LocalPlayer.Character hum = char.Humanoid hum.Changed:connect(function() script.Parent.Frame.Healthbar.Health.Size = UDim2.new(hum.Health/hum.MaxHealth-0.02,0,0.8,0) end) local p=game.Players.LocalPlayer local c=p.Character or p.CharacterAdded c:WaitForChild'Humanoid'.Changed:connect(function() script.Parent.Frame.Healthbar.Health.Size=UDim2.new(c.Humanoid.Health/c.Humanoid.MaxHealth-.02,0,.8,0) end) |
|
|
| Report Abuse |
|
|
Ahrinmor
|
  |
| Joined: 25 Dec 2012 |
| Total Posts: 534 |
|
|
| 31 Jan 2015 07:25 PM |
| With that none of it works at all. |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2015 07:27 PM |
Put;
repeat wait() until game.Players.LocalPlayer
In the beginning of your script
Like before everything |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 31 Jan 2015 07:27 PM |
| No, that's just a useless wait() |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2015 07:28 PM |
| Its a localscript, It can run before the player joins |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
| |
|
|
| 31 Jan 2015 07:37 PM |
Is it inside a localscript? if so, do this. player = game.Players.LocalPlayer character = player.Character hum = cahracter.Humanoid |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
| |
|
|
| 31 Jan 2015 07:40 PM |
Quote from the wiki:
"do not run server-side, but instead, perform their actions on the client" |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 31 Jan 2015 07:41 PM |
| Are you dumb? We are not even "arguing" about that, we are "arguing" about whether they run before the PLAYER exists. |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2015 07:42 PM |
| they dont run before the player exists. how would they? |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2015 07:43 PM |
| A local script that runs on the client cannot run before the client even exists. #logic |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2015 07:47 PM |
| rofl, "localscripts can run before their parent client exists" ayy |
|
|
| Report Abuse |
|
|
| |
|