How to get humanoind local script

So my current script just throws error at me when I’'m trying to get a humanoid via local player. The error is attempt to index nil with ‘Humanoid’. Are there any variants how to solve avoid that happening?

local player = game.Players.LocalPlayer

local hum = player.Character.Humanoid

mouse.Button1Down:Connect(function()
	if hum.Health < hum.MaxHealth then
			hum.Health = hum.MaxHealth
2 Likes

The Humanoid instance is not created yet when you try to get it, just wait for it until is placed, something like this:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hum = character:WaitForChild("Humanoid")
warn(hum)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.