Search code examples
luarobloxluau

Attempt to index nil with humanoid


I tried to apply a Humanoid Description on a player that joined the game but the output gives an error: "Attempt to index nil with humanoid". Heres is the code.

game.Players.PlayerAdded:Connect(function(Player)
    Player.Character.Humanoid:ApplyDescription(game.ServerStorage.HumanoidDescription)
end)

Solution

  • You should wait for the Character to load in the game. Before applying the HumanoidDescription.

    game.Players.PlayerAdded:Connect(function(Player)
        Player.CharacterAdded:Connect(function(character)
           wait()
           character:WaitForChild("Humanoid"):ApplyDescription(game.ServerStorage.HumanoidDescription)
        end)
    end)