Stellar AI

Errors

Roblox 'attempt to index nil with' Error – Causes & Fix

The error

Players.Name.PlayerGui.LocalScript:5: attempt to index nil with 'Humanoid'

What it means

You tried to read a property from something that is nil. Often player.Character hasn't spawned yet, FindFirstChild returned nil, or a Touched part isn't a character.

The fix

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
-- Touched handler example
part.Touched:Connect(function(hit)
    local hum = hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid")
    if not hum then return end
    hum.Health -= 10
end)

Use CharacterAdded:Wait() for the character, WaitForChild for things that load in, and always nil-check FindFirstChild results.

Related tools: Roblox script generator · Roblox Lua error fixer · all script generators