I have been trying to make it so the GUI shows the Players Max Health which increases every level. However it's as if everything I try doesn't work right, and only works half of the time. Sometimes it will find the Character, sometimes it wont. I've tried everything I could think of but it wont fix. Can someone help me please? The code is inside a Local script in the PlayerGui. This is the Code:
local player = game.Players.LocalPlayer
local Char = player.Character
local Humanoid = Char.Humanoid
local LevelData = player:WaitForChild('LevelData')
local Level = LevelData:WaitForChild('Level')
while true do
wait(0.2)
Humanoid.MaxHealth = 100+(3*(player.LevelData.Level.Value*player.PlayerGui.BonusDamage.Value))
player.PlayerGui.Power.Value = Humanoid.MaxHealth
script.Parent.Text = Humanoid.MaxHealth
end
The error output in-game on the ROBLOX Developer Console in the Client Log is:
Players.Knucklehead_Ninja.PlayerGui.Stats.Frame.HealthNumber.LocalScript:3: attempt to index local 'Char' (a nil value)
Stack Begin
Script 'Players.Knucklehead_Ninja.PlayerGui.Stats.Frame.HealthNumber.LocalScript', Line 3
Stack End

3 comments
Thanks so much this works perfectly. ^_^
Please accept this answer if it answers your question.
Just a heads up, but you can simply do local char = player.Character or player.CharacterAdded:wait().