Why is humanoid nil?

every local script i write it is always nil i have to find an way to fix it

here is the code

local deltaTime = 1

local RunService = game:GetService("RunService")
local AbbModule = require(game.ReplicatedStorage.Shared.Abbreviation)

local Player = game.Players.LocalPlayer
local Character = workspace:WaitForChild(Player.Name)
local Humanoid = Character["Humanoid"]

local PlayerDisplay = script.Parent
local PlayerImage = PlayerDisplay.PlayerImage
local Frame = PlayerDisplay.Frame

local HealthBar = Frame.HealthBar
local HealthRound = Frame.HealthRound
local LevelRound = Frame.LevelRound
local EXPRound = Frame.EXPRound
local EXPText = EXPRound.EXPText
local HealthText = Frame.HealthText
local LevelText = LevelRound.LevelText

-- functions
local function GetPlayerImage()
	-- thumbnail stuff
	local userId = Player.UserId
	local thumbType = Enum.ThumbnailType.HeadShot
	local thumbSize = Enum.ThumbnailSize.Size60x60
	local content, isReady = game.Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
	
	PlayerImage.ImageColor = Color3.fromRGB(255,255,255)
	PlayerImage.Image = content
end

local function HealthBar()
	-- sizing stuff
	HealthText.Text = AbbModule:Abbreviate(Humanoid.Health).." / "..AbbModule:Abbreviate(Humanoid.MaxHealth)
	HealthRound:TweenSize(UDim2.new(Humanoid.Health / Humanoid.MaxHealth, 0, .362, 0))
end

local function LevelBar()
	LevelText.Text = "Level: "..AbbModule:Abbreviate(Player.Stats.GameValues.Level.Value)
end

local function EXPBar()
	EXPText.Text = AbbModule:Abbreviate(Player.Stats.GameValues.EXP.Value).." / "..AbbModule:Abbreviate(Player.Stats.GameValues.RequiredEXP.Value)
end

coroutine.resume(coroutine.create(function()
	while true do
		wait(deltaTime)
		LevelBar()
		EXPBar()
		HealthBar()
		GetPlayerImage()
	end
end))
2 Likes

Humanoid isn’t loaded yet.

try:

local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
4 Likes

Try putting this after you create an index for player

if Player.Character == nil then
wait()
return
end

and then index the Character