Start building

How to Fix "attempt to index nil with 'Humanoid'" in Roblox Studio

Roblox Studio OutputCharacter Error
attempt to index nil with 'Humanoid'
30-Second Fix

Why it happens & how to fix it

The character isn't spawned yet (or `hit.Parent` is nil/not a character). Wait for the character with `player.Character or player.CharacterAdded:Wait()` and use `FindFirstChildOfClass("Humanoid")` with an `if` guard.

Broken codeCauses error
-- LocalScript (BROKEN!)
local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid -- crashes on join!
Working fixSafe Luau
-- LocalScript (FIXED!)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid") :: Humanoid

Root cause & debugging checklist

When a LocalScript starts right as the player joins, `player.Character` is often still `nil` for a few frames. Accessing `player.Character.Humanoid` immediately crashes. In `Touched` listeners, parts touching baseplates or destroyed accessories also lack a Humanoid.

  • Always write `local character = player.Character or player.CharacterAdded:Wait()`.
  • Use `character:WaitForChild('Humanoid')` when initializing character scripts.
  • Inside Touched callbacks, guard with `local hum = hit.Parent and hit.Parent:FindFirstChildOfClass('Humanoid')`.

Common questions.

Does WaitForChild work after the player dies and respawns?

Put character scripts inside StarterCharacterScripts so they automatically re-run with the new character after every respawn.

More Roblox error fixes.

All 12 error guides

Revix reads Studio Output
and fixes bugs automatically.

Start building free

Free to start. No card needed.