local plr = game.Players.LocalPlayer local dispHealth = script.Parent local numHealth = dispHealth.Parent.healthNumber local human = workspace:FindFirstChild(plr.Name).Humanoid dispHealth.Size.X.Offset = human.Health * 2
Error message: Players.scourge495.PlayerGui.ScreenGui.healthBG.healthBar.Script:4: attempt to index a nil value
I am fetching the local Player that this script is attached to in line 1, and then i use it as a reference to try and fetch the player models humanoid.
I have attempted it without the additional '.Humanoid' and it finds the players model just fine. Also I have tried :FindFirstChild("Humanoid") whilst creating a new variable in the process but the same error message occurs when it attempts to extract a humanoid.
I'm a bit new to scripting but not programming, so simple slipups are still probably happening under my nose. If anyone would be as kind to tell me what aspect I'm missing i'd greatly appreciate it. Thanks!
In a localscript in starterGui, you should do this:
repeat wait() until game:GetService("Players").LocalPlayer local plr = game.Players.LocalPlayer local numHealth = script.Parent.Parent.healthNumber local human = game.workspace:FindFirstChild(plr.Name) dispHealth.Size.X.Offset = human.Health * 2
Is this a local script?. Im assuming it is not due to the error line saying .script and not .LocalScript But if you are still doing a normal script just do plr = script.Parent.Parent.Parent.Parent.Parent humanoid = game.Workspace[plr.Name] If it is a local script i think the issue might be ur using () and not [] on line 4